我已经多次看过这个问题,但经过广泛的观察,我没有找到一个成功的答案。
我正在尝试为Outlook创建一个脚本,该脚本会自动将带有附件的电子邮件转发回发件人,并附带包含原始附件的更新消息。除了我做什么之外,所有工作除了我无法转发附件。如果我只使用.Forward,则不包括附件。如果我尝试使用.Attachment属性,它会破坏脚本。
CODE:
Sub ForwardEmail(Item As Outlook.MailItem)
With Item.Forward
.Attachments.Add Item.Attachment
.Subject = ("APPROVED - ") & Item.Subject
.Recipients.Add Item.SenderEmailAddress
.Body = "Your timesheet has been approved." & vbCrLf & Item.Body
.Send
End With
End Sub
答案 0 :(得分:0)
Microsoft Outlook(以及Gmail,Yahoo等其他电子邮件引擎)的设计方式如下:
因此,请使用此代码。它遵循上面提到的规则#2,即无论何时转发电子邮件,附件都将自动附加。
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 = ("APPROVED - ") & Item.Subject
oMail.HTMLBody = "Your timesheet has been approved." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add Item.SenderEmailAddress
oMail.Save
oMail.Send
End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub