传递电子邮件时,如何自动转发到Outlook电子邮件以外的其他电子邮件以及发件人的附件

时间:2019-05-25 16:04:34

标签: vba outlook

当传递到我的收件箱的特定电子邮件只是转发具有相同附件和正文的邮件,而只是更改主题并将其自动转发到某些电子邮件时,我正在尝试使用vba这个脚本创建脚本 发件人向我发送电子邮件时,我需要这些顺序自动进行 所以这是我的宏脚本

Private Sub Application_Startup()
Set objInbox = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
Set objInboxItems = objInbox.Items
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim objMail As Outlook.MailItem
Dim objForward As Outlook.MailItem

If TypeOf Item Is MailItem Then
   Set objMail = Item

   'If it is a specific new email
   If (objMail.SenderEmailAddress = "someone@outlook.com") And 
(objMail.Importance = olImportanceHigh) And (objMail.Attachments.Count > 0) 
Then

       Set objForward = objMail.Forward
       'Customize the forward subject, body and recipients
       With objForward
            .Subject = "Custom Subject"
            .HTMLBody = "<HTML><BODY>Type body here. </BODY></HTML>" & 
objForward.HTMLBody
            .Recipients.Add ("someone@gmail.com")
            .Recipients.ResolveAll
            .Importance = olImportanceHigh
            .Send
       End With
   End If
End If
End Sub

Sub myAutoFW()

End Sub

注意:我不需要手动转发,只是当某人发送电子邮件时,我想将其转发到多个电子邮件,而不是自动转发。打开我的界面,站在收件箱中的电子邮件上,运行宏,但没有任何反应

1 个答案:

答案 0 :(得分:2)

您可以尝试类似的方法。当您收到新邮件并进行转发时,预计转发的邮件通常至少会发送给新用户,因此所有内容均保持不变(即不会删除附件)。

Sub ForwardEmail(item As Outlook.MailItem)
  Dim oMail As MailItem    

  On Error GoTo ErrorHandler
  If oMail.Attachments.Count > 0 Then
   If item.Class = olMail Then
     Set oMail = item.Forward
     With oMail
        .Subject = .Subject 'Can change the subject here
        .HTMLBody = "Please find attached." & vbCrLf & .HTMLBody
        .Recipients.Add "someone@gmail.com" 'email address here
        .Save
        .Send
     End With
  End If
 End If
 ErrorHandler:
  Set oMail = Nothing
End Sub