简体   繁体   中英

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. Now, the requirement here is to access exchange server (Microsoft OWA) of my organization for sending mails in asp.net code.

Is it possible? If yes, then plz throw some light.

Thnx

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 ?? 'coz EWS is not supported in there. Please update any idea...?

You can send emails using the Exchange Web Services API (EWS). EWS is a set of old fashioned ASMX web services hosted on the same server as OWA. Microsoft has even published an open source managed API wrapper on GitHub for EWS.

Here is an example on how to send emails using EWS: http://code.msdn.microsoft.com/Send-Email-with-Exchange-50189e57

The GitHub readme also includes links to samples.

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.

Update regarding Exchange 2003:

You can access the Exchange 2003 mail store via HTTP using WebDAV. 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).

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. It uses Windows Authentication so it will not work if your Exchange 2003 OWA is set up to use FBA. If you need to use FBA let me know - I may have some sample code somewhere that you can use.

It is possible to send email through your organizations exchange server from asp.net, but you wouldn't want to use OWA.

There is a web site dedicated to .Net email that should give you some sample code. See: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM