我收到了来自两个发件人的邮件,其中包含两个主题,并且发往特定的地址。
我制定了一条规则:
from: example@example.com or example2@example2.com sent to: me@me.com and with: Company return doc or Daily document Country in the subject except if the subject contains "FW:"
运行脚本:
Sub myRuleMacro(Item As Outlook.MailItem)
Dim selEmail As Outlook.MailItem
Set selEmail = ActiveExplorer.Selection.Item(1).Forward
selEmail.Recipients.Add "address@address.pl"
selEmail.Send
Set selEmail = Nothing
End Sub
该脚本适用于所选电子邮件,但是要选择它,我需要手动单击它,或者如果已经单击/标记了任何其他电子邮件,它将转发此标记的电子邮件,而不是规则中的电子邮件。
如何从规则中选择邮件以触发宏?
基本上,我需要可以转发电子邮件的解决方案。由于公司安全政策,我无法使用转发规则。
答案 0 :(得分:1)
大家都知道了,应该是
示例
Option Explicit
Public Sub myRuleMacro(Item As Outlook.MailItem)
Dim selEmail As Outlook.MailItem
If TypeOf Item Is Outlook.MailItem Then
Set selEmail = Item.Forward
selEmail.Subject = Item.Subject
selEmail.HTMLBody = Item.HTMLBody
selEmail.Recipients.Add "address@address.pl"
selEmail.Save
selEmail.Send
End If
End Sub
不需要Selection.Item
,并确保在发送前先save
答案 1 :(得分:0)
触发规则的电子邮件已经传递到子Item as Outlook.MailItem
-Sub myRuleMacro(**Item As Outlook.MailItem**)
使用Set selEmail = ActiveExplorer.Selection.Item(1).Forward
您应该能够简单地使用Item.Forward
尝试
Sub myRuleMacro(Item As Outlook.MailItem)
Dim newForward as MailItem
Set newForward = Item.Forward
newForward.Recipients.Add "address@address.pl"
newForward.Send
End Sub
编辑:在评论中包含@Tony Dallimore的更新。