通过Exchange Webservies Api从Azure发送邮件
我使用Exchange Webservies Api创建了具有电子邮件发送功能的云项目.但是,当我在azure上部署解决方案时,它给出以下错误:-
位于Microsoft.Exchange的Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsRequest.CreateServiceResponse()的Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse..ctor()处,Microsoft.Exchange的Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse..ctor() Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetUserSettings(Web站点上的.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute()(在Microsoft.Exchange.WebServices.Autodiscover上列出1个smtpAddresses,列表1个设置,可为null的1个请求版本,Uri& autodiscoverUrl). .AutodiscoverService.GetSettings [TGetSettingsResponseCollection,TSettingName](在Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 identities,List`1 settings,Nullable` 1 requestVersion,GetSettingsMethod`2 getSettingsMethod,Func`1 getDomainMethod)中. 1个smtpAddresses,列出"1"设置),位于Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUs Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress,UserSettingName [] userSettingNames)处的erSettings(字符串smtpAddress,列出的1个请求设置),Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(字符串emailSmtpAddress,UserSettingName [] userSettingNames)(字符串电子邮件地址,ExchangeVersion请求的服务器版本, Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress,AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)的Microsoft.Exchange.WebServices.Data.Exchange.AutoWeb.NET中的AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback).WebDefault.Page_Load(Object sender,EventArgs e)中的AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
"Microsoft.Exchange.WebServices.Strings"的类型初始值设定项引发了异常. "
此消息已从代码引发的异常中捕获.我使用了 URL 中的代码.
请让我知道这里的问题,或者任何机构都知道如何在没有任何第三方服务帮助的情况下从azure发送邮件.
谢谢,
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,
因此,以下是利用EWS托管API 1.1通过EWS(Exchange Web服务)发送电子邮件的基本代码段(在此处下载):
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url =新的Uri(
"https://red002.mail.emea.microsoftonline.com/ews/exchange.asmx");
service.Credentials =新的WebCredentials(用户名,密码);
var message = new EmailMessage(service);
message.ToRecipients.Add("joe@doe.com");
message.From =新的EmailAddress(
"foobarbaz@windowsazure.emea.microsoftonline.com");
message.Subject =您好,电子邮件-来自Windows Azure";
message.Body =新的MessageBody(BodyType.HTML,来自da cloud的电子邮件:)");
message.SendAndSaveCopy();
在上面的代码中,我正在通过欧洲的EWS主机发送电子邮件-您可能需要使用不同的URL作为您的位置:
亚太(APAC):https://red003.mail.apac.microsoftonline.com
欧洲,中东和非洲(EMEA):https://red002.mail.emea.microsoftonline.com
北美:https://red001.mail.microsoftonline.com
希望这会有所帮助.
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.