簡體   English   中英

根據收件人設置發件人電子郵件地址

[英]Setting the sender email address according to the recipient

如何以編程方式在我回復的電子郵件中設置發件人地址到收件人地址?

在此處輸入圖片說明

VBA有辦法嗎? 我不知道從哪里開始,所以我很抱歉,因為我無法顯示任何代碼。

感謝@Al Bundy 糾正了這一點。 此解決方案基於此帖子

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

Outlook 不允許您將郵件發件人設置為任意電子郵件地址 - 您必須具有明確的權限(在 Exchange 的情況下)才能設置MailItem.SentOnBehalfOfName屬性。 如果是 POp3/SMTP 帳戶,請設置MailItem.Account屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM