1
votes

Below Outlook rules is supposed to save the attachment from [email protected] with Gift Card Purchase subject line to disk then move the email to the Delete Items folder so that it won't process it again. The rule runs when it receives the new email and moved the email to the Delete Items folder but it did not save the attachment.

I suspect the rule move the message to the Delete Items folder first then execute the script to save the email attachment which is no longer in the Inbox folder.

I cannot change the sequence of the Outlook rule below to execute the script first then move the message but Outlook does not allow.

Any recommendation?

Apply this rule after the message arrives
from [email protected]
 and with Gift Card Purchase in the subject
 and on this computer only
move it to the Deleted Items folder
 and run Project1.SaveAttachment
Public Sub SaveAttachment(MItem As Outlook.MailItem)
    Dim oAttachment As Outlook.Attachment
    Dim sSaveFolder As String
    sSaveFolder = "C:\Temp\"
    For Each oAttachment In MItem.Attachments
        oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    Next
End Sub
1
Move the item to Deleted folder inside the script so you won't need extra rule for deletion. Also add some error handling to your rule because it may crash with certain item types.miroxlav
After further testing, the rule moves the email to Deleted Items FIRST then save the attachments from the next email in the Inbox folder. Is there a way to save the attachment FIRST then move email? I cannot change the order of the rule... Once I select move to specific folder and run a script, the rule executes the move function first then execute the script. Hoping to add logic in the script to move email to the "Deleted Items" folder then I can remove the move it to the Deleted Items folder option in the rule.Brandon168

1 Answers

0
votes

Work with MailItem.Delete Method (Outlook) with in your code

Update you rule by removing move it to the Deleted Items folder then add following to your code MItem.Delete after Next

Example

For Each oAttachment In MItem.Attachments
    oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next

MItem.Delete