none
Moving Emails with an email attachment to specific folder RRS feed

  • Question

  • Hello Team,

    My requirement is to check the email that has an email attachment when they arrive and move to its sub folder in the outlook. It has to move only if the email attachment is from some specific domain like for EX: IBM.com, CSC.com. Please let me know if we can create a Macro for this.

    Thank you



    • Edited by Premcdp2 Thursday, December 21, 2017 11:36 AM
    Thursday, December 21, 2017 11:34 AM

Answers

  • Hello Premcdp2,

    You could create a macro to confirm if the mail contains attachment and then move it to target folder.

    Here is the simply macro to move the mail to a sub folder in Inbox folder.

    Sub MovingMail(Item As MailItem)
    Dim TargetFolder As Folder
    Set TargetFolder = Application.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox).Folders("Test")
    If Item.Attachments.Count > 0 Then
    Item.Move TargetFolder
    End If
    End Sub

    And you need create a rule to handle arrived mail item. 

    In the rule, you could select condition "with specific words in the sender's address" and then set IBM.com as the specific words. So the rule will only handle mails which's sender mail contains IBM.com. 

    And then for the actions, you could select "run a script" to run a macro to check if the mail contains attachments and move it. If you are using Outlook 2016, the option "run a script" may miss in the list and you could refer to below link to add this option.

    The option to "Run a Scritp" has disappeared from the Outlook rules. 

    The rule setting should look like this.

    Then you could save the rule and send a mail with attachments for testing.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 22, 2017 8:03 AM

All replies

  • Hello Premcdp2,

    You could create a macro to confirm if the mail contains attachment and then move it to target folder.

    Here is the simply macro to move the mail to a sub folder in Inbox folder.

    Sub MovingMail(Item As MailItem)
    Dim TargetFolder As Folder
    Set TargetFolder = Application.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox).Folders("Test")
    If Item.Attachments.Count > 0 Then
    Item.Move TargetFolder
    End If
    End Sub

    And you need create a rule to handle arrived mail item. 

    In the rule, you could select condition "with specific words in the sender's address" and then set IBM.com as the specific words. So the rule will only handle mails which's sender mail contains IBM.com. 

    And then for the actions, you could select "run a script" to run a macro to check if the mail contains attachments and move it. If you are using Outlook 2016, the option "run a script" may miss in the list and you could refer to below link to add this option.

    The option to "Run a Scritp" has disappeared from the Outlook rules. 

    The rule setting should look like this.

    Then you could save the rule and send a mail with attachments for testing.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 22, 2017 8:03 AM
  • Thank you for your reply. I am not clear I think in the requirement, Let me re clarify it with an example

    The Email i receive have another email as an attachment. I want to Move the Mails to a Folder on the Basis of the attached mail domain. For Example, The Mail i received also have a mail as an attachment and that attached mail is from IBM.com so i wanna move this main mail to a folder.

    Can we Create a Macro for this Requirement.

    Thanks



    • Edited by Premcdp2 Wednesday, January 3, 2018 12:44 PM
    Wednesday, January 3, 2018 12:36 PM
  • Hi Premcdp2,

    >> The Mail i received also have a mail as an attachment and that attached mail is from IBM.com so i wanna move this main mail to a folder.

    It is possible.

    For your requirement, we could split into these parts, fire an event while receiving new mail, get attachment email in the event, check the from address of the attachment mail and move the mail.

    I would suggest you post different threads for different parts, and then we could focus on different small requirement.

    With the suggestion from Terry, do you have any issue with moving a mail to a specific Folder?

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 5, 2018 5:54 AM
  • Sure. I will do that. Thank you for the reply
    Friday, January 5, 2018 7:13 AM
  • Hi Tao Zhou,

    Even I Have a similar Requirement.

    Can you Help me With This type of Macro.

    Best Regards

    Ankush Jain

    Tuesday, March 6, 2018 1:56 PM
  • Hi Ankush,

    For your issue, I would suggest you post a new thread, and you could reference this thread in your new thread.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 7, 2018 2:32 AM