[英]Send mails using EXCHANGE SERVER (Microsoft Outlook web access)in asp.net
I know how to send mails using outlook installed in same machine, where I'm running my code. 我知道如何使用安装在运行我的代码的同一台计算机上的Outlook发送邮件。 Now, the requirement here is to access exchange server (Microsoft OWA) of my organization for sending mails in asp.net code. 现在,这里的要求是访问我组织的交换服务器(Microsoft OWA),以便以asp.net代码发送邮件。
Is it possible? 可能吗? If yes, then plz throw some light. 如果是,那么请给我一些启示。
Thnx n
UPDATE 更新
Got the Solution. 得到了解决方案。 Posting my working code here for any one who wants help. 在这里将我的工作代码发布给任何需要帮助的人。 happy coding ! 编码愉快!
protected void Button1_Click(object sender, EventArgs e)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.AutodiscoverUrl("youremailaddress@yourdomain.com");
service.Url = new Uri("https://yourwebmailaddress.com/ews/Exchange.asmx");
service.UseDefaultCredentials = true;
//service.Credentials = new WebCredentials("username", "password");
EmailMessage message = new EmailMessage(service);
message.Subject = "My auto mail from exchange server";
message.Body = "hi everyone !";
message.ToRecipients.Add("brad.pitt@hollywood.com");
message.Save();
message.SendAndSaveCopy();
Label1.Text = "Success !";
}
Another Question: How to use microsoft exchange 2003 ?? 另一个问题:如何使用Microsoft Exchange 2003? 'coz EWS is not supported in there. 那里不支持'coz EWS。 Please update any idea...? 请更新任何想法...?
You can send emails using the Exchange Web Services API (EWS). 您可以使用Exchange Web服务API(EWS)发送电子邮件。 EWS is a set of old fashioned ASMX web services hosted on the same server as OWA. EWS是与OWA托管在同一服务器上的一组老式ASMX Web服务。 Microsoft has even published an open source managed API wrapper on GitHub for EWS. 微软甚至在GitHub上为EWS发布了一个开源托管的API包装器。
Here is an example on how to send emails using EWS: http://code.msdn.microsoft.com/Send-Email-with-Exchange-50189e57 这是有关如何使用EWS发送电子邮件的示例: http : //code.msdn.microsoft.com/Send-Email-with-Exchange-50189e57
The GitHub readme also includes links to samples. GitHub自述文件还包括示例链接。
Usually EWS can be found at http://yourexchangeserver/ews/exchange.asmx
but with the managed API you can use autodiscovery to automatically find the address of EWS on your Exchange server. 通常,可以在http://yourexchangeserver/ews/exchange.asmx
上找到EWS,但是通过托管API,您可以使用自动发现功能自动在Exchange服务器上查找EWS的地址。
Update regarding Exchange 2003: 有关Exchange 2003的更新:
You can access the Exchange 2003 mail store via HTTP using WebDAV. 您可以使用WebDAV通过HTTP访问Exchange 2003邮件存储。 WebDAV is a bit of a pain to use because you may have to use Forms Based Authentication (FBA) if that is what your OWA installation requires (in comparison EWS can use Windows Authentication even if OWA on Exchange 2007/2010 is using FBA). 使用WebDAV有点麻烦,因为如果您的OWA安装需要它,则可能必须使用基于表单的身份验证(FBA)(相比之下,即使Exchange 2007/2010上的OWA使用FBA,EWS仍可以使用Windows身份验证)。
I have never tried sending mails using WebDAV for Exchange (although I have used WebDAV for a number of other things) but I found an example on MSDN that you may want to try. 我从未尝试使用WebDAV for Exchange发送邮件(尽管我已经将WebDAV用于许多其他事情),但是我在MSDN上找到了一个您可能想尝试的示例 。 It uses Windows Authentication so it will not work if your Exchange 2003 OWA is set up to use FBA. 它使用Windows身份验证,因此,如果将Exchange 2003 OWA设置为使用FBA,它将无法使用。 If you need to use FBA let me know - I may have some sample code somewhere that you can use. 如果您需要使用FBA,请告诉我-我可能在某些地方可以使用一些示例代码。
It is possible to send email through your organizations exchange server from asp.net, but you wouldn't want to use OWA. 可以从asp.net通过组织交换服务器发送电子邮件,但您不想使用OWA。
There is a web site dedicated to .Net email that should give you some sample code. 有一个专门用于.Net电子邮件的网站,该网站应为您提供一些示例代码。 See: http://www.systemnetmail.com/ 请参阅: http : //www.systemnetmail.com/
Understand that you will need to get the exchange administrator to give your asp.net machine access to the SMTP port (this usually Port 25) on the exchange server and set up permissions to allow you to relay messages thru the server. 请理解,您将需要让交换管理员授予asp.net计算机对交换服务器上SMTP端口(通常是端口25)的访问权限,并设置权限以允许您通过服务器中继邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.