Forward Email with its attachment in Outlook 2010

后端 未结 2 617
时光说笑
时光说笑 2020-12-07 02:26

The below code (I pulled from several sources) now works in that when I receive an email with specific words in the subject line it triggers a script that runs the below.

2条回答
  •  佛祖请我去吃肉
    2020-12-07 02:57

    There is no need to use the Explorer object in the code:

    Sub ForwardEmail(item As Outlook.MailItem)
      Dim oMail As MailItem    
    
      On Error GoTo Release
    
      If item.Class = olMail Then
         Set oMail = item.Forward
         oMail.Subject = oMail.Subject
         oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
         oMail.Recipients.Add "email address here"
    
         oMail.Save
         oMail.Send
      End If
     Release:
      Set oMail = Nothing
      Set oExplorer = Nothing
    End Sub
    

    You may find the Getting Started with VBA in Outlook 2010 article helpful.

提交回复
热议问题