Forward Email with its attachment in Outlook 2010

后端 未结 2 618
时光说笑
时光说笑 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:52

    There is an unnecessary condition

    If oExplorer.Selection.item(1).Class = olMail Then
    

    that may cause the forwarding to be bypassed.

    Sub ForwardEmail(item As Outlook.MailItem)
    ' Dim oExplorer As Outlook.Explorer
    Dim oMail As MailItem
    ' Set oExplorer = Application.ActiveExplorer
    
    On Error GoTo Release
    
    ' If oExplorer.Selection.item(1).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
    

提交回复
热议问题