none
From list on a new mailitem RRS feed

  • Question

  • Hi

    When I click on the From button when creating a new mailitem from Outlook for versions 2013+, how is the list populated?

    It appears to show current accounts and also allows the addition of other email addresses. Can I access or re-create the generated list through the outlook OO via C# interop?

    Thanks

    Allan

    Monday, January 22, 2018 4:09 AM

Answers

  • It contains two parts: the list of all mail accounts (you can get it from Application.Session.Accounts). The second part (editable list with "x"s next to the emails) comes from the registry, where the manually added addresses are stored.

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

    Monday, January 22, 2018 1:51 PM
  • Not easily - you'd need Extended MAPi (C++ or Delphi) or ProfMan to handle them - the biggest problem, is that the Account object does not have PropertyAccessor like other OOM objects.

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

    • Marked as answer by allanjs Tuesday, January 23, 2018 5:41 PM
    Tuesday, January 23, 2018 4:31 PM

All replies

  • It contains two parts: the list of all mail accounts (you can get it from Application.Session.Accounts). The second part (editable list with "x"s next to the emails) comes from the registry, where the manually added addresses are stored.

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

    Monday, January 22, 2018 1:51 PM
  • Thank Dmitry.

    Can the entries in the registry be easily extracted?

    Tuesday, January 23, 2018 6:57 AM
  • Hi allanjs,

    below is the code example to access Account details.

    using System; 
    using System.Text; 
    using Outlook = Microsoft.Office.Interop.Outlook; 
    
    namespace OutlookAddIn1 
    { 
     class Sample 
     { 
     public static void DisplayAccountInformation(Outlook.Application application) 
     { 
    
     // The Namespace Object (Session) has a collection of accounts. 
     Outlook.Accounts accounts = application.Session.Accounts; 
    
     // Concatenate a message with information about all accounts. 
     StringBuilder builder = new StringBuilder(); 
    
     // Loop over all accounts and print detail account information. 
     // All properties of the Account object are read-only. 
     foreach (Outlook.Account account in accounts) 
     { 
    
     // The DisplayName property represents the friendly name of the account. 
     builder.AppendFormat("DisplayName: {0}\n", account.DisplayName); 
    
     // The UserName property provides an account-based context to determine identity. 
     builder.AppendFormat("UserName: {0}\n", account.UserName); 
    
     // The SmtpAddress property provides the SMTP address for the account. 
     builder.AppendFormat("SmtpAddress: {0}\n", account.SmtpAddress); 
    
     // The AccountType property indicates the type of the account. 
     builder.Append("AccountType: "); 
     switch (account.AccountType) 
     { 
    
     case Outlook.OlAccountType.olExchange: 
     builder.AppendLine("Exchange"); 
     break; 
    
     case Outlook.OlAccountType.olHttp: 
     builder.AppendLine("Http"); 
     break; 
    
     case Outlook.OlAccountType.olImap: 
     builder.AppendLine("Imap"); 
     break; 
    
     case Outlook.OlAccountType.olOtherAccount: 
     builder.AppendLine("Other"); 
     break; 
    
     case Outlook.OlAccountType.olPop3: 
     builder.AppendLine("Pop3"); 
     break; 
     } 
    
     builder.AppendLine(); 
     } 
    
     // Display the account information. 
     System.Windows.Forms.MessageBox.Show(builder.ToString()); 
     } 
     } 
    }

    Reference:

    Account Object (Outlook)

    Regards

    Deepak


    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.

    Tuesday, January 23, 2018 6:59 AM
    Moderator
  • Thanks for you reply Deepak

    The problem I have is where users wish to use email addresses for shared mailboxes where an associated account for the shared mailbox has not been added their outlook accounts.

    Iterating through the accounts collection in this case doesn't help as the mailbox was most likely automapped.

    I'm currently writing a routine to verify the address they enter is a valid recipient in the GAL when it's not in their current accounts collection. I then use namespace.getsharedDefaultFolder to validate the entered address is trying to access a shared mailbox. 

    I was hoping there was a shortcut to pull the entries from the registry rather have them redo the process in my application.

    Regards

    Allan



    • Edited by allanjs Tuesday, January 23, 2018 7:22 AM
    Tuesday, January 23, 2018 7:16 AM
  • Not easily - you'd need Extended MAPi (C++ or Delphi) or ProfMan to handle them - the biggest problem, is that the Account object does not have PropertyAccessor like other OOM objects.

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

    • Marked as answer by allanjs Tuesday, January 23, 2018 5:41 PM
    Tuesday, January 23, 2018 4:31 PM