[英]Change 'FROM' field in reply event for a shared mailbox
問題描述:
我必須更改郵件的發件人('來自'字段)。 我添加了兩個共享郵箱帳戶,當我點擊該項目的回復時,我想從其他共享郵箱發送此回復郵件。
我的(不工作)解決方案:
我使用了_Reply事件。 我正在更改屬性.SentOnBehalfOfName,分配第二個共享郵箱的電子郵件地址。 消息編輯器中的“發件人”字段更改為正確的地址,但是在發送消息后,收到消息的人看到我從第一個電子郵件地址發送消息,並在我的“已發送項目”文件夾中,消息顯示為代表發送“第二個電子郵件地址”。
我的代碼(位於thisOutlookSession中):
Option Explicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean
Public WithEvents myOlApp As Outlook.Application
Public strSender1 As String 'name of shered mailbox which is owner of the mail
Public strSender2 As String 'address of shered mailbox
Private Sub Application_Startup()
Set oExpl = Application.ActiveExplorer
bDiscardEvents = False
End Sub
Private Sub oExpl_SelectionChange()
On Error Resume Next
Set oItem = oExpl.Selection.Item(1)
End Sub
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
strSender1 = "Name of mailbox1"
strSender2 = "mailbox2@dsg.dk"
If Response.Class = olMail Then
If Response.Sender Is Nothing Then
'MsgBox "There's no sender for the current email", vbInformation
Exit Sub
End If
If Response.Sender = strSender1 Then
MsgBox "Field 'From' has been changed to " + strSender2
Response.SentOnBehalfOfName = strSender2
End If
End If
MsgBox Response.SentOnBehalfOfName
'Set oItem = Nothing
End Sub
出於您的目的,我認為您需要SendUsingAccount
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
strSender1 = "Name of mailbox1"
If Response.Class = olMail Then
If oItem.AutoForwarded = True Then
If oItem.Sender = strSender1 Then
' oItem was autoforwarded from
' strSender1 - name of shared mailbox which is owner of the mail
Response.SendUsingAccount = Session.Accounts.Item(1)
MsgBox "Field 'From' has been changed to " + strSender1
End If
End If
End If
End Sub
要確定帳號:
Private Sub AccountNames()
Dim i As Long
For i = 1 To Session.Accounts.Count
Debug.Print " Account " & i & " DisplayName....: " & _
Session.Accounts.Item(i).DisplayName
Debug.Print
Next i
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.