Search code examples
c#asp.netexchangewebservices

How to get receiver email from a sent email in EWS?


I'm looping sent item in EWS, and try to show details of each sent emails, receiver, subject, body etc. However, I found receiver in the sent email message is null. How to get receiver email address? My code:

ItemId id = (ItemId)Request["id"]; // this id is the item id of WellKnownFolderName.**SentItems**
        EmailMessage current = EmailMessage.Bind(service, id);
        La_Subject.Text = current.Subject;
        La_From.Text = current.Sender.ToString();
        La_Sent.Text = current.DateTimeReceived.ToString();
        La_To.Text = current.ReceivedBy.ToString(); // This line error occurs

Any idea?


Solution

  • To get the recipients of a mail, use the DisplayTo and DisplayCC properties of the mail message.

    Or iterate through the ToRecipients collection yourself and build the string yourself:

    var toRecipients = string.Join(", ",
        mail.ToRecipients.Select(
            address => string.Format("\"{0}\" <{1}", address.Name, address.Address)));
    

    The ReceivedBy property is used in delegate scenarios. See http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.emailmessage.receivedby(v=exchg.80).aspx.