none
MAPI, Set From field on new messages in Outlook 2010? RRS feed

  • Question

  • In Outlook 2010, when you display the From field, there's a handy new dropdown that shows who you're sending from.  Is there any programmatic way to set the From field when a new email is created, through MAPI?  So when the user creates a new email, the From field is filled in with whatever value I'm trying to put in there.

    It looks like it gets this value from the PR_DISPLAY_NAME from the profile section, and/or the "Account Name" reg key associated with the service provider it's using to create the email.  But all my attempts to change these values while Outlook is running have been problematic.  Any ideas?

    Friday, September 24, 2010 1:22 AM

Answers

  • Just wanted to update this thread...  We were able to find a solution for this.

    For each of the user's addresses, we needed to create a new Message Service, with a Transport Provider, storing the email address in the PR_IDENTITY props for the transport provider.  This populated Outlook 2010's From dropdown.  And a call to IMsgServiceAdmin::MsgServiceTransportOrder adjusted the order so that the Default Send address came first.

    Outlook doesn't log in the new services until it's restarted, so the user has to restart Outlook for these changes to take effect.  But after the restart, this works.

    • Marked as answer by Kevin Deus Friday, December 10, 2010 2:07 AM
    Friday, December 10, 2010 2:07 AM

All replies

  • You basically change the MailItem.Sender property, as outlined here:

    How to: Create a Sendable Item for a Specific Account Based on the Current Folder (Outlook):
    http://msdn.microsoft.com/en-us/library/ff866712.aspx


    (P.S. Please don't forget to mark this post as an answer if it has helped you)
    Eric Legault: MVP (Outlook), MCTS (SharePoint)
    Owner: Collaborative Innovations
    Twitter: elegault
    Blog: Eric Legault My Eggo
    Friday, September 24, 2010 4:52 PM
    Moderator
  • Alright, I'll give that a shot.  The other half of that is I'd need to intercept when Outlook creates a new email.  I'd like to always fill in the From field whenever the user creates a new message.  Is there a way to do that?
    Friday, September 24, 2010 5:48 PM
  • Yes, capture the Inspectors.NewInspector event:

    Inspectors.NewInspector Event (Outlook):
    http://msdn.microsoft.com/en-us/library/ff867841.aspx

    You'll have to determine if the Inspector.CurrentItem object is a MailItem.  If it is, retrieve your MailItem object from that and you can then capture MailItem events as well.


    (P.S. Please don't forget to mark this post as an answer if it has helped you)
    Eric Legault: MVP (Outlook), MCTS (SharePoint)
    Owner: Collaborative Innovations
    Twitter: elegault
    Blog: Eric Legault My Eggo
    • Proposed as answer by Supersau Thursday, September 10, 2015 11:03 AM
    Friday, September 24, 2010 6:24 PM
    Moderator
  • And is there a way to do this from the point of view of a MAPI provider?

    What's going on under the surface when it runs the line, "mail.Sender = addrEntry;"?  Is this setting PR_SENDER_* properties on the IMessage object?  Is it also sending events to Outlook to notify it that the From field should change?

    More specifically, if I'm overriding IMAPIFolder::CreateMessage and I want the new message to come from a different sender, are there some properties I can set so that Outlook will change the From field?

     

    Friday, September 24, 2010 10:57 PM
  • Outlook sets the account id and and account name properties to those of the default account. it does not touch the PR_SENDER_xyz properties.

    Have you tried to set the InternetAccountName and InternetAccountStamp properties?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, September 27, 2010 2:06 PM
  • It looks like InternetAccountName and InternetAccountStamp require account info from an IOlkAccount.  Does this mean that any address you can send from needs to be added into the IOlkAccountManager?  If the user types a new email address into the From field, does that automatically create a new IOlkAccount for that address?

    I'm able to get the functionality I want with a simple VB script to set mail.Sender, and according to MFCMapi, it looks like this just sets PR_SENT_REPRESENTING_* props on the message.  But trying to reproduce the same behavior from within our message store provider isn't working.  I can set the props on a newly-created message, but when OL displays the message, the From field isn't displaying the right value.  If I close and reopen the message, then it does.  Is there a fnevObjectModified notification event I can send to fix this, or anything along those lines?

    Monday, September 27, 2010 11:18 PM
  • What transport provider are you using?

    SMTP provider ignores the values of the PR_SENT_REPRESENTING_ properties, and Exchange requires an explicit permission to send on behalf of the specified user.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, September 27, 2010 11:30 PM
  • We have our own custom transport provider, and checking whether the user has permission to send as that address is handled on the server.  And the mail is sent through an IConverterSession, which does make use of the PR_SENT_REPRESENTING props.

    But the problem I'm having is long before the message hits the transport provider.  The problem is getting the right address to show up in the UI, just after the message is created.  Everything else works fine.

    Monday, September 27, 2010 11:50 PM
  • It sure sounds like the ages old problem of Outlook caching the stale data and only refreshing after an object is completely released and reopened...

    I don't think there is anything you can do unless you use the Outlook Objet Model to set the MailItem.SendUsingAccount property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Tuesday, September 28, 2010 6:03 AM
  • Just wanted to update this thread...  We were able to find a solution for this.

    For each of the user's addresses, we needed to create a new Message Service, with a Transport Provider, storing the email address in the PR_IDENTITY props for the transport provider.  This populated Outlook 2010's From dropdown.  And a call to IMsgServiceAdmin::MsgServiceTransportOrder adjusted the order so that the Default Send address came first.

    Outlook doesn't log in the new services until it's restarted, so the user has to restart Outlook for these changes to take effect.  But after the restart, this works.

    • Marked as answer by Kevin Deus Friday, December 10, 2010 2:07 AM
    Friday, December 10, 2010 2:07 AM