none
How to change sender name while opening mail in message window RRS feed

  • Question

  • HI All,

    I have one requirement where while opening the mail from in box item , I would like to display different sender mail / name in message window. 

    I have handled Open event of MailItem. Here, I have tried with properties MailItem.Sender.Address, MailItem.Sender.Name and MailItem.SendUsingAccount, but nothing is working. For your further information, I have attached screenshot. I would like to change address from libdarkclient@gmail.com to xyz@abc.com.

    Please help.

    Thanks

    Devendra

    Thursday, August 17, 2017 4:15 PM

All replies

  • Firstly, temporary changing anything in Outlook does not really work - it will get you no matter what you do. Do your modifications once as soon as you can and do that before Outlook opens it (or it might not see the changes).

    To change the sender, you will need to change a dozen or so PR_SENDER_xyz and PR_SENT_REPRSENTING_xyz MAPI properties (take a look at a message with OutlookSpy - click IMessage button). Note that the Outlook Object Model (being the big brother) won't let you set these properties. You will need Extended MAPI (C++ or Delphi) or Redemption (any language) to do that. The sample script below resets the sender of the currently selected message in Outlook (you can run it from OutlookSpy if you click the Script button and paste the script):

    set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    strEntryID = Session.AddressBook.CreateOneOffEntryID("Fake User", "SMTP", "someuser@fake.domain.com", false, true)
    set addressEntry = Session.AddressBook.GetAddressEntryFromID(strEntryID)
    
    set Msg = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
    
    Msg.Sender = addressEntry
    Msg.SentOnBehalfOf = addressEntry
    Msg.Save
    


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 17, 2017 4:33 PM
  • Hello,

    As Dmitry said, Outlook object model does not let us set the sender for a received item. You may use Redemption to get your expected result.

    Here is my test code:

    Dim myMail As MailItem
    Dim myAddressList As AddressList
    Dim myAddressEntry As AddressEntry
    Set myAddressList = Application.GetNamespace("MAPI").AddressLists("Contacts")
    Set myAddressEntry = myAddressList.AddressEntries(1)
    Dim objMsg As Object
    Set objMsg = GetCurrentItem()
    If TypeOf objMsg Is Outlook.MailItem Then
    Set myMail = objMsg
    myMail.Sender = myAddressEntry
    End If

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 18, 2017 7:59 AM
    Moderator