Question

I am using EWS Managed API to send email. I am getting a Microsoft.Exchange.WebServices.Data.ServiceResponseException: EmailAddress or ItemId must be included in the request.

In the Soap return XML I see ErrorMissingInformationEmailAddress : This error occurs if the EmailAddress (NonEmptyStringType) element is missing.

Which email address is it talking about?

Using Exchange 2007 SP1. Exchange credentials are correct and the to/from email addresses are valid emails. Any ideas? Google has not helped.

Same code has worked for other Exchange Servers. service.AutodiscoverUrl() does not work for this server.

using Microsoft.Exchange.WebServices.Data;

protected void SendEwsMail()
    {
        //Trust all certificates
        System.Net.ServicePointManager.ServerCertificateValidationCallback =
            ((sender, certificate, chain, sslPolicyErrors) => true);

        var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new NetworkCredential("user@domain.com", "password");
        service.Url = new Uri("Url");

        var email = new EmailMessage(service);

        email.ToRecipients.Add("user@domain.com");

        email.From = new EmailAddress("user@domain.com");
        //email.ReplyTo.Add(recipient.FromAddress);
        email.Sender = new EmailAddress("user@domain.com");

        email.Subject = "test";

        // Send the message and save a copy.
        email.SendAndSaveCopy();
    }
Was it helpful?

Solution

It turns out that for the mail Server (MS Exchange) in question I needed to use this method:

Writing an encrypted mail via Exchange Web Services

var item = new EmailMessage(service);
item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content);
// Set recipient infos, etc.
item.Send();

It seems to be because of the encrypyed MIME attachment. Using the standard To, From, Subject properties of the Microsoft.Exchange.WebServices.Data.EmailMessage class does not work correctly.

Although it does work as expected when the mail server was SmarterMail.

SmarterMail 9.x is one of the only mail servers (including Microsoft Exchange) to support Exchange Web Services (EWS). (from http://blogs.smartertools.com/tag/exchange-web-services/)

Anyone know why SmarterMail would behave differently to MS Exchange?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top