根据收件人设置发件人邮箱

Setting the sender email address according to the recipient

如何以编程方式在我回复的电子邮件中设置发件人地址到收件人地址?

VBA有办法吗?我不知道从哪里开始,所以很抱歉,因为我无法显示任何代码。

Outlook 不会让您将邮件发件人设置为任意电子邮件地址 - 您必须有明确的许可(如果是 Exchange)才能设置 MailItem.SentOnBehalfOfName 属性。如果是 POp3/SMTP 帐户,请设置 MailItem.Account 属性.

感谢@Al Bundy 更正此问题。此解决方案基于 this post.

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