我的Outlook中有很多邮箱,我已经设置了以下代码来处理我的一个非默认邮箱(requests@address.com)上的传入邮件。
我希望代码处理到达此框的所有邮件,对内容执行操作,然后回复该邮件。
问题是ReplyAll只包含邮箱本身作为收件人(requests@address.com)而不包括发件人。结果是发送者没有得到响应,但是盒子在循环中自己发送和接收。如果原件中有多个人,则他们会收到邮件的副本,但不会收到发件人本人。
使用ReplyAll时,如何让邮箱正确识别发件人作为收件人而不是邮箱本身? 任何见解都表示赞赏!提前谢谢:)
Option Explicit
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim olRecip As Recipient
Set olNs = Application.GetNamespace("MAPI")
Set olRecip = olNs.CreateRecipient("requests@address.com") '// Owner's Name or email address
Set Inbox = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox)
Set Items = Inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Debug.Print Item.Subject
Dim myReply As Outlook.MailItem
Set myReply = Item.ReplyAll
myReply.htmlbody = "Replied At: "& Now()
myReply.SentOnBehalfOfName = "requests@address.com"
myReply.Send
End If
End Sub
答案 0 :(得分:1)
为确保发件人包含在myReply中,您可以将Item.SenderEmailAddress添加到myReply.To。
如果Item.SenderEmailAddress为" requests@address.com"。
,您可以退出答案 1 :(得分:0)
试试这个
Private Sub Items_ItemAdd(ByVal Item As Object)
Dim Recip As Recipient
If TypeOf Item Is Outlook.MailItem Then
Debug.Print Item.Subject
Set Item = Item.ReplyAll
Set Recip = olReply.Recipients.Add Item.SenderEmailAddress
Recip.Type = olTo
Item.HTMLBody = "Replied At: " & Now()
Item.display
End If
End Sub