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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="760f190304131b171f1a17121204130505360f19030412191b171f185815191b">[email protected]</a>");

    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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f4e4f7f2b8e6ffe2e2d6fef9fafaefe1f9f9f2b8f5f9fb">[email protected]</a>");
    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…?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x