views:

295

answers:

2

How can I , from a custom c# application, create and send/receive mails from MS Exchange?

I am assuming this is not directly possible with the standard framework mail classes.

If I could say that this needs to work with MS Exchange 2003 and 2007 what are my options?

Ideally I dont want to buy a third party component so if this is possible with c# then what are the steps for creating a library that can send a new mail or receive a mail into a custom application.

The C# app will be local, as in the same network as the Exchange server.

A: 

There's a number of routes to look at: MAPI, CDO, 3rd party libraries etc.

What version of Exchange is it you're working with as I think 2007 has some web services that you can use that OWA plugs in to.

Chris W
OWA relies on Outlook I assume? Dont want to have any client dependencies that will cost. Is there not a way to connect to EXchange (2003 , 2007) using c#. The Exchange server is on the network, we are not talking remote here.
Coolcoder
@Coolcoder: OWA from a technical standpoint does not rely on Outlook. Not sure about the cost (licensing) though.
Alfred Myers
@Chris W: The requirement to run on both 2003 and 2007 excludes Exchange Web Services (EWS) from the possible alternatives.
Alfred Myers
I've used the MAPI approach against a 2003 server in the past with an app that needed to deal with incoming e-mail - it did the job for me but I don't know exactly what your app needs to do. There's plenty of POP3 libraries you could look at as well that would do the job if your Exchange server allows POP access.
Chris W
+1  A: 

Have you tried using the built-in .Net mail assemblies?

If you create an SmtpClient client = new SmtpClient("my-email-server"), does smtp.Send not work?

----- with code

If the machine has a mail account setup then no, it should use the ones from the system so long as you set DefaultNetworkCredentials:

SmtpClient smtp = new SmtpClient("mailserver"); 
smtp.Credentials = CredentialCache.DefaultNetworkCredentials; 

You can create some though and use those instead:

SmtpClient client = new SmtpClient("myserver"); 
client.Credentials = new NetworkCredential("username", "password", "domain");
Antony Koch
Do you not need special credentials to send/receive vis MS Exchange?
Coolcoder
If the machine has a mail account setup then no, it should use the ones from the system so long as you set DefaultNetworkCredentials:SmtpClient smtp = new SmtpClient("mailserver"); smtp.Credentials = CredentialCache.DefaultNetworkCredentials;You can create some though and use those instead:SmtpClient client = new SmtpClient("myserver");client.Credentials = new NetworkCredential("username", "password", "domain");
Antony Koch
@Antony: Please edit/update your answer putting the code in the comment above in the answer itself.
Alfred Myers