Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

I created cloud project with email sending functionality using Exchange Webservies Api. But when I deployed the solution on azure it give below error :-


"at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse..ctor() at Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsRequest.CreateServiceResponse() at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.ReadSoapBody(EwsXmlReader reader) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute() at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetUserSettings(List`1 smtpAddresses, List`1 settings, Nullable`1 requestedVersion, Uri& autodiscoverUrl) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 settings, Nullable`1 requestedVersion, GetSettingsMethod`2 getSettingsMethod, Func`1 getDomainMethod) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 smtpAddresses, List`1 settings) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List`1 requestedSettings) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) at WebRole1._Default.Page_Load(Object sender, EventArgs e)
The type initializer for 'Microsoft.Exchange.WebServices.Strings' threw an exception. "


This message has been caught from Exception raised by code. I have used the code from URL.

Please let me know what's the issue here Or does any body know how to send the mail from azure without any third party service help.

Thanks,
Posted

1 solution

So, here is the essential code snippet to send an email via EWS (Exchange Web Services) by leveraging the EWS Managed API 1.1 (get the download here):

var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri(
"https://red002.mail.emea.microsoftonline.com/ews/exchange.asmx");
service.Credentials = new WebCredentials(userName, password);

var message = new EmailMessage(service);
message.ToRecipients.Add("joe@doe.com");
message.From = new EmailAddress(
"foobarbaz@windowsazure.emea.microsoftonline.com");
message.Subject = "Hello EMail - from Windows Azure";
message.Body = new MessageBody(BodyType.HTML, "Email from da cloud :)");

message.SendAndSaveCopy();

In the code above I am sending the email via the EWS host for Europe – you may need different URLs for your location:

Asia Pacific (APAC): https://red003.mail.apac.microsoftonline.com
Europe, the Middle East, and Africa (EMEA): https://red002.mail.emea.microsoftonline.com
North America: https://red001.mail.microsoftonline.com

Hope this helps.
 
Share this answer
 
Comments
harshal rajkotia 17-Oct-12 7:42am    
Mukesh : Thanks for the solution

My issue is solved now. Actually I was using EWS API version 2.0.
When I changed the version 1.2, sending mail functionality started working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900