Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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("[email protected]");

    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("[email protected]");
    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...?

like image 501
Kings Avatar asked Jun 20 '11 13:06

Kings


1 Answers

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.

like image 57
Jakob Christensen Avatar answered Sep 20 '22 14:09

Jakob Christensen