我的工作 Outlook 2010 帐户收到大量垃圾邮件。我提供了我们的垃圾邮件拦截器地址,以便将垃圾邮件(作为附件)转发到。
我想单击功能区上的一个图标(我已经有了这个)并运行 VBA 代码来获取当前消息,将其附加到新消息,将地址添加到新消息,发送新消息,然后删除原始消息。(删除可以是将邮件放在“已删除邮件”文件夹中,也可以将其永久删除。)
解决了!!!!
这是完全符合我要求的代码。我在网上找到它并对其进行了修改以满足我的需要。
Sub ForwardAndDeleteSpam()
'
' Takes currently highlighted e-mail, sends it as an attachment to
' spamfilter and then deletes the message.
'
Set objItem = GetCurrentItem()
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.Attachments.Add objItem, olEmbeddeditem
.Subject = "SPAM"
.To = "spamfilter@schools.nyc.gov"
.Send
End With
objItem.Delete
Set objItem = Nothing
Set objMsg = Nothing
End Sub
Function GetCurrentItem() As Object
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = Application.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = Application.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
Set objApp = Nothing
End Function