Description of the problem:
I have to change the sender ('from' field ) of a message. I added two shared mailbox accounts and while I'm clicking reply on the item, which belongs to one of them, I want to send this reply message from the other shared mailbox.
My (not working) solution:
I used event _Reply. I'm changing the property .SentOnBehalfOfName, assigning the email address of the second shared mailbox. The 'from' field in the message editor changes to the proper address, but after sending the message the person who received it sees that I sent it from the first email address and in my "sent items" folder the message appears as sent on behalf of "second email address".
My code (located in 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
For your purposes I think you need 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
To determine the account number:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.