vba 将当前邮件作为附件转发然后删除原始邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14589250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forward current message as attachment then delete original message
提问by user2022673
I get a lot of spam messages on my work Outlook 2010 account. I am provided with our spam blocker address to forward the spam (as an attachment) to.
我的工作 Outlook 2010 帐户收到了大量垃圾邮件。我提供了我们的垃圾邮件拦截器地址以将垃圾邮件(作为附件)转发到。
I'd like to click on an icon on the ribbon (I already have this) and have VBA code run that takes the current message, attaches it to a new message, adds an address to the new message, sends the new message and then deletes the original message. (Deleting can be either putting the message in the "Deleted Items" folder or permanently deleting it.)
我想点击功能区上的一个图标(我已经有了这个)并运行 VBA 代码来获取当前消息,将其附加到新消息,向新消息添加地址,发送新消息,然后删除原始消息。(删除可以是将邮件放入“已删除邮件”文件夹或永久删除它。)
SOLVED!!!!
解决了!!!!
Here is code that does exactly what I want. I found it on the net and modified it to meet my needs.
这是完全符合我想要的代码。我在网上找到了它并对其进行了修改以满足我的需要。
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 = "[email protected]"
.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
回答by thommck
You can use this to go through a selection of emails, rather than just one by adapting the code as follows
您可以使用它来浏览一系列电子邮件,而不仅仅是通过如下修改代码
Sub ForwardSpamToNetworkBox()
On Error Resume Next
Dim objItem As Outlook.MailItem
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.Attachments.Add objItem, olEmbeddeditem
.Subject = "SPAM"
.To = "[email protected]"
.Send
End With
objItem.Delete
Next
Set objItem = Nothing
Set objMsg = Nothing
End Sub
This was created with info from http://jmerrell.com/2011/05/21/outlook-macros-move-email
这是使用来自http://jmerrell.com/2011/05/21/outlook-macros-move-email 的信息创建的
Ideally, instead of deleting, I'd move it to a subfolder called "Submitted" but I can't get that to work in Public Folders
理想情况下,我不会删除它,而是将其移动到名为“已提交”的子文件夹中,但我无法在公共文件夹中使用它