Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, June 15, 2017 12:36 PM
I am trying to send email using the Exchange Web Service from a .Net Web API solution.
My solution is using ASPNet Identity Mixed Authentication, with which I configured the EWS to user DefaultCredentials. I received "No mailbox with such guid".
I can user a dedicated Username and password by assigning the credentials and it does work.
I can use defaultcredentials on my local (domain) development machine, but when I deploy the solution it returns the error.
To test it I created a simple Application using ONLY Windows Authentication, with a Web Api method to send a test email, using defaultcredentials.
This is the EwsResponse...
<Trace Tag="EwsResponse" Tid="127" Time="2017-06-15 12:23:55Z" Version="15.00.0913.015">
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="845" MinorBuildNumber="34" Version="V2016_10_10" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:CreateItemResponseMessage ResponseClass="Error">
<m:MessageText>No mailbox with such guid.</m:MessageText>
<m:ResponseCode>ErrorNonExistentMailbox</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:MessageXml>
<t:Value Name="MailboxGuid">S-1-5-21-137024685-2204166116-4157399963-374383</t:Value>
</m:MessageXml>
<m:Items />
</m:CreateItemResponseMessage>
</m:ResponseMessages>
</m:CreateItemResponse>
</s:Body>
</s:Envelope>
</Trace>
Any clues?
Thanks.
All replies (3)
Thursday, June 15, 2017 12:39 PM
Here is my simple method to send the email...
public HttpResponseMessage Get() {
try
{
Trace.WriteLine($"User: {User.Identity.Name}");
var exchangeService = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
var url = @"https://autodiscover.domain.ac.uk/ews/exchange.asmx";
exchangeService.Url = new Uri(url);
exchangeService.UseDefaultCredentials = true;
exchangeService.TraceEnabled = true;
exchangeService.TraceEnablePrettyPrinting = true;
exchangeService.TraceFlags = TraceFlags.All;
exchangeService.TraceListener = new TraceListener();
var subject = "This is a test message for the exchange web service";
var emailMessage = new EmailMessage(exchangeService);
emailMessage.Subject = subject;
emailMessage.Body = subject;
emailMessage.ToRecipients.Add(new EmailAddress("[email protected]"));
emailMessage.SendAndSaveCopy(WellKnownFolderName.SentItems);
return Request.CreateResponse(HttpStatusCode.OK);
}
catch(Exception ex) {
Trace.WriteLine(ex);
throw;
}
}
Thursday, June 15, 2017 2:16 PM
A little further information...
The "MailboxGuid" (S-1-5-21-137024685-2204166116-4157399963-374383) is actually the SID of the IIS Server that is running the Website.
I have no idea why EWS is using that ID.
Friday, June 16, 2017 5:46 AM
You have used
exchangeService.UseDefaultCredentials = true;
If your using Impersonation in IIS you need to ensure Kerberos delegation is also configured see https://blogs.msdn.microsoft.com/emeamsgdev/2012/11/05/ews-from-a-web-application-using-windows-authentication-and-impersonation/ which has an example and explanation of what is needed.
Cheers
Glen