当将特定的电子邮件发送到我的收件箱中以自动发送电子邮件至带有附件和身体的多个电子邮件地址时,我想要的。
。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
我站在收件箱中的电子邮件上并运行宏,但什么也没发生。
您可以尝试这样的事情。当您收到新邮件并转发时,预计转发的邮件通常至少向新用户发送给新用户,因此所有内容都保持原样(即未删除附件(。
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