none
[EWS]: How get the current user's own email address or check entered, using Exchange Web Services? RRS feed

  • Question

  • I have to work with external Exchange server. How can I get the own email address or check address entered by the user (that he introduced exactly own address), using EWS?
    Email address is not the same as username.
    Thursday, August 25, 2016 4:33 PM

Answers

  • You can use ConvertId with a generic address and Exchange will then return the PrimarySMTP for that mailbox eg

                Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
                AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, Inbox.Id.UniqueId, "mailbox@domain.com");
                AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
                Console.WriteLine(((AlternateId)aiResponse).Mailbox);

    AutoDiscover will also return the PrimarySMTP address of a Mailbox is you do a POX based discovery

    To check other addresses you can also use ResolveName https://msdn.microsoft.com/en-us/library/office/dn645423(v=exchg.150).aspx

    Cheers
    Glen

    • Marked as answer by vangog63 Tuesday, September 6, 2016 9:13 AM
    Friday, August 26, 2016 2:22 AM

All replies

  • You can use ConvertId with a generic address and Exchange will then return the PrimarySMTP for that mailbox eg

                Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
                AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, Inbox.Id.UniqueId, "mailbox@domain.com");
                AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
                Console.WriteLine(((AlternateId)aiResponse).Mailbox);

    AutoDiscover will also return the PrimarySMTP address of a Mailbox is you do a POX based discovery

    To check other addresses you can also use ResolveName https://msdn.microsoft.com/en-us/library/office/dn645423(v=exchg.150).aspx

    Cheers
    Glen

    • Marked as answer by vangog63 Tuesday, September 6, 2016 9:13 AM
    Friday, August 26, 2016 2:22 AM
  • Thank you, Glen.
    The first method looks a not legal and I doubt that it would always work.
    To use the AutoDiscover I must have an address. But AutoDiskover not help me to match the name to the address. As I will get results for all addresses if I have the rights.
    ResolveName will not give me a definite answer.
    Correct me if I'm in something wrong.
    Tuesday, August 30, 2016 12:55 PM
  • >>The first method looks a not legal and I doubt that it would always work.

    It does work and is legitimate my suggestion is you test it yourself

    >>To use the AutoDiscover I must have an address. But AutoDiskover not help me to match the name to the address. As I will get results for all addresses if I have the rights.

    That's incorrect you need to test this yourself to see how it actually works you can use something like the EWSEditor https://ewseditor.codeplex.com/ (or just use Outlook ) to test this without writing any code (the ewseidtor also uses the first method I mentioned). Autodiscover returns the PrimarySMTPAddress as a separate result based on the user being discovered.

    Your other options are to query Active Directory directly using LDAP (eg system.directoryservices etc)

    Tuesday, August 30, 2016 11:54 PM