none
Outlook auto send e-mail when e-mail in folder is opened RRS feed

  • Question

  • Hi 

    Is there a macro that will automatically sends an e-mail when any e-mail in a specified folder is opened? 

    Thanks

    Dave

    Tuesday, September 27, 2016 6:13 PM

Answers

  • Hi Dave_Chatham,

    you had mentioned that ,"Is there a macro that will automatically sends an e-mail when any e-mail in a specified folder is opened?".

    you need to write the code that can fulfill your exact requirement.

    you want to send E-mail automatically. but to whom?

    following is some suggestion on that you can try to work to fulfil your requirement.

    you had mentioned that "Any specified folder is opened"

    so here you need an event that can fire when you change the folder. then you need to check that the current folder is your specified folder or not. if it different folder then do nothing. if it is a specified folder then get the details of selected mail and send to the desired mail address.

    you can use Explorer.SelectionChange Event (Outlook) that can fire when you change folder.

    This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder. However, this event does not occur if the folder is a file-system folder or if any folder with a current Web view is displayed. This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).

    Explorer.SelectionChange Event (Outlook)

    Following is the code to send mail

    Public Sub CreateNewMessage()
    Dim objMsg As MailItem
    
    Set objMsg = Application.CreateItem(olMailItem)
    
     With objMsg
      .To = "email_id"
      .CC= "email_id"
      .BCC = "email_id"
      .Subject = "This is the subject"
      .Categories = "Test"
      .VotingOptions = "Yes;No;Maybe;"
      .BodyFormat = olFormatPlain 
      .Importance = olImportanceHigh
      .Sensitivity = olConfidential
      .Attachments.Add ("path-to-file.docx")
      
      .Display
    .send
    End With
    
    Set objMsg = Nothing
    End Sub
    

    if you want to send the mail to the from address of the selected mail then you can use the code mentioned below.

    Public Sub CreateNewMessage()
    Dim objMsg As MailItem
    Dim Selection As Selection
    Dim obj As Object
    
    Set Selection = ActiveExplorer.Selection
    
    For Each obj In Selection
    
    Set objMsg = Application.CreateItem(olMailItem)
    
     With objMsg
      .To = obj.SenderEmailAddress
      .Subject = "This is the subject"
      .Categories = "Test"
      .Body = "My notes" & vbcrlf & vbcrlf & obj.Body 
      .Display
    ' use .Send to send it automatically 
    
    End With
    Set objMsg = Nothing
    
    Next
    
    End Sub
    

    so you can try to follow the steps mentioned above to fulfil your requirement.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, September 28, 2016 4:17 AM
    Moderator

All replies

  • Hello Dave,

    Nope. There is no such ready macro available out of the box. But you can create one. See Getting Started with VBA in Outlook 2010 for more information.

    Basically you need to handle the NewInspector event of the Inspectors class which is fired whenever a new inspector window is opened, either as a result of user action or through program code. Then you can access the item is to be opened and check where it comes from.

    The Parent property of the Outlook items which returns the parent Object of the specified object (a MAPIFolder in our case).


    [custom.development]

    Tuesday, September 27, 2016 6:57 PM
  • Hi Dave_Chatham,

    you had mentioned that ,"Is there a macro that will automatically sends an e-mail when any e-mail in a specified folder is opened?".

    you need to write the code that can fulfill your exact requirement.

    you want to send E-mail automatically. but to whom?

    following is some suggestion on that you can try to work to fulfil your requirement.

    you had mentioned that "Any specified folder is opened"

    so here you need an event that can fire when you change the folder. then you need to check that the current folder is your specified folder or not. if it different folder then do nothing. if it is a specified folder then get the details of selected mail and send to the desired mail address.

    you can use Explorer.SelectionChange Event (Outlook) that can fire when you change folder.

    This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder. However, this event does not occur if the folder is a file-system folder or if any folder with a current Web view is displayed. This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).

    Explorer.SelectionChange Event (Outlook)

    Following is the code to send mail

    Public Sub CreateNewMessage()
    Dim objMsg As MailItem
    
    Set objMsg = Application.CreateItem(olMailItem)
    
     With objMsg
      .To = "email_id"
      .CC= "email_id"
      .BCC = "email_id"
      .Subject = "This is the subject"
      .Categories = "Test"
      .VotingOptions = "Yes;No;Maybe;"
      .BodyFormat = olFormatPlain 
      .Importance = olImportanceHigh
      .Sensitivity = olConfidential
      .Attachments.Add ("path-to-file.docx")
      
      .Display
    .send
    End With
    
    Set objMsg = Nothing
    End Sub
    

    if you want to send the mail to the from address of the selected mail then you can use the code mentioned below.

    Public Sub CreateNewMessage()
    Dim objMsg As MailItem
    Dim Selection As Selection
    Dim obj As Object
    
    Set Selection = ActiveExplorer.Selection
    
    For Each obj In Selection
    
    Set objMsg = Application.CreateItem(olMailItem)
    
     With objMsg
      .To = obj.SenderEmailAddress
      .Subject = "This is the subject"
      .Categories = "Test"
      .Body = "My notes" & vbcrlf & vbcrlf & obj.Body 
      .Display
    ' use .Send to send it automatically 
    
    End With
    Set objMsg = Nothing
    
    Next
    
    End Sub
    

    so you can try to follow the steps mentioned above to fulfil your requirement.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, September 28, 2016 4:17 AM
    Moderator