Sending E-Mail in C#

Posted by pm_2 on Stack Overflow See other posts from Stack Overflow or by pm_2
Published on 2010-05-28T11:41:03Z Indexed on 2010/05/28 11:41 UTC
Read the original article Hit count: 152

Filed under:
|
|

I’m using .NET 3.5, and I want to automatically send a mail. I’m currently using the following:

Microsoft.Office.Interop.Outlook.MailItem mailMsg = 
    (Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem(
     Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailMsg.To = recipient;
mailMsg.Subject = subject;
mailMsg.Body = body;
mailMsg.Send();

However, I’ve found several articles that seem to imply I should be using the following method:

System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
mailmsg.To = recipient;
mailmsg.Subject = subject;
mailmsg.Body = body;

Can anyone tell me what the difference between the two namespaces if, and why you might want to use one over the other?

© Stack Overflow or respective owner

Related posts about c#

Related posts about email