[英]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.