vba Outlook宏有条件地发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1125194/
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
outlook macro to send email conditionally
提问by 76mel
Could anyone guide me in creating an Outlook Macro that does the following: Whenever I send a mail to a particular mail-id an automated mail will be send to a specified group pa mail-ids or some outlook contacts group.
任何人都可以指导我创建执行以下操作的 Outlook 宏:每当我向特定邮件 ID 发送邮件时,自动邮件将发送到指定组 pa 邮件 ID 或某些 Outlook 联系人组。
Thanks in advance!!
提前致谢!!
回答by 76mel
Here is a quick piece of VBA for you to get going with, add it in your ThisOutlookSession module.
这是一个快速的 VBA 供您使用,将其添加到您的 ThisOutlookSession 模块中。
you should be able to do the CC via a rule as well from the tools menu, or write the code to create a rule !
您应该也可以通过工具菜单中的规则执行 CC,或者编写代码来创建规则!
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.MessageClass = "IPM.Note" Then
For Each myRecipient In Item.Recipients
If myRecipient.Address = "<EMAIL ADDRESS TO FIND>" Then
''SendNotification
SendNotificationWithCopy Item
End If
Next
End If
End Sub
Sub SendNotification()
Set objMail = Application.CreateItem(olMailItem)
objMail.Recipients.Add "<EMAIL ADDRESS/GROUP TO SEND NOTIFICATION>"
objMail.Recipients.ResolveAll
objMail.Subject = "NOTIFICATION"
objMail.Body = "Body Text"
objMail.Send
End Sub
Sub SendNotificationWithCopy(obj As Object)
Set objMail = Application.CreateItem(olMailItem)
objMail.Recipients.Add "<EMAIL ADDRESS TO SEND NOTIFICATION>"
objMail.Recipients.ResolveAll
objMail.Attachments.Add obj, OlAttachmentType.olEmbeddeditem
objMail.Subject = "NOTIFICATION with attachment"
objMail.Body = "Body Text"
objMail.Send
End Sub