none
Automatic forward emails from a folder

    Question

  • Hi all!

    I would like to ask if it is posible to create automatic folders in Outlook to forward emails with some conditions. What I like to create is a folder, which when I drag an email inside it do the following actions:

    - Pick an email address (always the same)

    - Change subject to another one which will be always the same.

    - Erase the format so it doesn't send images included in the body of the message.

    - Send the email with the attachments (PDFs).

    I have no idea if it is possible to do this with a VBA macro or if this a common code already available.

    Many thanks in advance! :)


    • Edited by Diaño Thursday, March 14, 2019 8:48 PM
    Thursday, March 14, 2019 8:46 PM

All replies

  • Hello Diano,

    Yes, you can develop a VBA macro or add-in to get the required functionality. Basically you need to handle the ItemAdd event which is fired when one or more items are added to the specified collection. This event does not run when a large number of items are added to the folder at once.

    Public WithEvents myOlItems As Outlook.Items 
    
    Public Sub Initialize_handler() 
     
     Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items 
     
    End Sub 
     
    
    Private Sub myOlItems_ItemAdd(ByVal Item As Object) 
      
     Item.Subject = "New subject" 
     
    End Sub

    You may find the Getting started with VBA in Office article helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, March 15, 2019 4:46 AM
  • Hello and thanks Eugene!

    I have been taking a look at what you sent me and trying to figure it out, but I am totally new to VBA so I don't know if this is going to do what I want:

    Public WithEvents myOlItems As Outlook.Items
    
    Public Sub Initialize_handler()
     
     Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items
     
    End Sub
     
    
    Private Sub myOlItems_ItemAdd(ByVal Item As Object)
      
     Item.Subject = "Top Priority"
     BodyFormat = olFormatPlain
     Recipient = Item.Recipients.Add("Jon Doe")
     Forward.Send
     
    End Sub

    So, it should:

    - Change subject to top priority

    - Change the format of the email to plain

    - Choose recipient John Doe, who would be the alias. Can here an email address be directly choose? Like "hello@gmail.com"?

    - Send the email.

    I am also not sure about how I get the code "inside" a specific folder, and also if I have two available addresses in the session, how I choose the one to send the email from.

    What do you think? Many thanks again in advance!



    • Edited by Diaño Sunday, March 17, 2019 11:49 PM
    Sunday, March 17, 2019 11:45 PM
  • Hi again!

    I keep trying to build this thing, I have been looking at some examples and the Outlook documentation, and this is what I currently have:

    Public WithEvents myOlItems As Outlook.Items
    
    Public Sub Initialize_handler()
    
     Set myOlItems = Application.GetNamespace("MAPI")
     Set myFolder = myOlItems.GetDefaultFolder(olFolderInbox).Folders("News").Items
    
    End Sub
    
    
    Private Sub myFolder_ItemAdd(ByVal Item As Object)
    
     Item.Subject = "New subject"
     Item.BodyFormat = olFormatPlain
     Item.Recipient = Items.Recipients.Add("username@domain.com")
     Item.Send
    
    End Sub

    So "News" would be a subfolder of "Inbox" of the account shared@domain.com

    I don't know if this makes sense at all. And I still don't know how to choose between the two email accounts that I have in Outlook, so the email gets sent from the shared one.

    Thanks!



    • Edited by Diaño 1 hour 36 minutes ago
    1 hour 38 minutes ago