问题
How can I set programmatically in an email, to which I reply, the sender address to the recipient address?
Is there a way in VBA? I don't know where to start so I apologize because I cannot show any code.
回答1:
Credit to @Al Bundy for correcting this. This solution is based on this post.
In ThisOutlookSession
:
Option Explicit
Private WithEvents objMail As MailItem
Private assignmentHandled As Boolean
'Set MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail And Not assignmentHandled Then
Set objMail = Item
End If
End Sub
'Handle reply/replayAll from triggering ItemLoad again
Private Sub objMail_Open(Cancel As Boolean)
assignmentHandled = True
End Sub
'Reply
Private Sub objMail_Reply(ByVal Response As Object, Cancel As Boolean)
Call SetSentOnBehalfOfName(Response)
End Sub
'Reply all
Private Sub objMail_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Call SetSentOnBehalfOfName(Response)
End Sub
'MailItem closed
Private Sub objMail_Close(Cancel As Boolean)
assignmentHandled = False
End Sub
' Avoid repeating code
Private Sub SetSentOnBehalfOfName(ByRef Response As Object)
Response.SentOnBehalfOfName = objMail.To
assignmentHandled = False
End Sub
回答2:
Outlook will not let you set message sender to an arbitrary email address - you must have an explicit permission (in case of Exchange) to set the MailItem.SentOnBehalfOfName
property. In case of a POp3/SMTP account, set the MailItem.Account
property.
来源:https://stackoverflow.com/questions/44019988/setting-the-sender-email-address-according-to-the-recipient