答案 0 :(得分:1)
归功于@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
答案 1 :(得分:0)
Outlook不允许您将邮件发件人设置为任意电子邮件地址 - 您必须具有明确的权限(如果是Exchange)才能设置MailItem.SentOnBehalfOfName
属性。如果是POp3 / SMTP帐户,请设置MailItem.Account
属性。