none
Converting "Ex" type email address to "SMTP" address RRS feed

  • Question

  • Hi,

      I am reading all the contacts from outlook in c# application using Microsoft.office.interop.outlook. My outlook is configured with Exchange server so I am getting exchange based email address. How to convert it into SMTP email address.

    Below I have given my code snippet.

    ApplicationClass outlookApplication = new ApplicationClass();
    NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI");
    MAPIFolder contacts = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    for (int i = 1; i < contacts.Items.Count + 1; i++)
    {
    ContactItem contact = (ContactItem)contacts.Items[i];
    Console.WriteLine(contact.Email1Address);
    }

    Thanks.

    Thursday, May 24, 2012 12:56 PM

Answers

  • First check that if the address is already SMTP - Email1AddressType will be "SMTP".

    If using Redemption is an option, use something like the following:

    Redemption.RDOSession session = new Redemption.RDOSession()
    session.Logon();
    Redemption.RDOFolder contacts = session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    Redemption.RDOItems items = contacts.Items;
    for (int i = 1; i < contacts.Items.Count + 1; i++)
    {
        RDOMail contact = (ContactItem)contacts [i];
        if (contact != null) //you can also have DLs
        {
            if ("SMTP" == contact.Email1AddressType)
            {
                Console.WriteLine(contact.Email1Address);
            }
            else
            {
                Redemption.RDOAddressEntry addressEntry = session.GetAddressEntryFromID(contact.Email1EnttryID)
                Console.WriteLine(addressEntry.SMTPAddress);
            }
        }
    }

    If you are already using Outlook.Application in your app, you can set RDOSession.MAPIOBJECT to Namespace.MAPIOBJECT instead of calling RDOSession.Logon.


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

    Tuesday, May 29, 2012 3:34 PM

All replies

  • what outlook version?
    Thursday, May 24, 2012 1:01 PM
  • Sorry for the late response Damian. I want to support all outlook versions (2003, 2007 and 2010).
    Monday, May 28, 2012 12:30 PM
  • First check that if the address is already SMTP - Email1AddressType will be "SMTP".

    If using Redemption is an option, use something like the following:

    Redemption.RDOSession session = new Redemption.RDOSession()
    session.Logon();
    Redemption.RDOFolder contacts = session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    Redemption.RDOItems items = contacts.Items;
    for (int i = 1; i < contacts.Items.Count + 1; i++)
    {
        RDOMail contact = (ContactItem)contacts [i];
        if (contact != null) //you can also have DLs
        {
            if ("SMTP" == contact.Email1AddressType)
            {
                Console.WriteLine(contact.Email1Address);
            }
            else
            {
                Redemption.RDOAddressEntry addressEntry = session.GetAddressEntryFromID(contact.Email1EnttryID)
                Console.WriteLine(addressEntry.SMTPAddress);
            }
        }
    }

    If you are already using Outlook.Application in your app, you can set RDOSession.MAPIOBJECT to Namespace.MAPIOBJECT instead of calling RDOSession.Logon.


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

    Tuesday, May 29, 2012 3:34 PM