Share via


About: System.Net.Mail (SNM)

API Type:  SMTP Sender

API Interface: .NET Framework Namespace Classes.

Business Logic: Sending mail via SMTP.

Language Support: .NET Languages only.

Direct Property Access:  N/A.

Product Versions: .NET Framework 2.0 and later (as of .NET 3.5).

 

Summary:

SNM is a pure .NET namespace for sending mail via SMTP.  System.Net.Mail replaces System.Web.Mail, which was a partial .NET wrapper for CDOSYS. SNM can is all .NET code.  

 

Backgrounders:

Collaboration Data Objects for Windows 2000 (CDOSYS)
https://msdn.microsoft.com/en-us/library/cc161087(v=exchg.65).aspx

CDO for Windows 2000
https://msdn.microsoft.com/en-us/library/ms527568(v=exchg.10).aspx

About CDO for Windows 2000
https://msdn.microsoft.com/en-us/library/ms527525(v=exchg.10).aspx

How to migrate the Collaboration Data Objects for NTS applications to Microsoft Collaboration Data Objects for Windows 2000
https://support.microsoft.com/kb/810702

Support policy for Microsoft Exchange APIs with the .NET Framework applications
https://support.microsoft.com/default.aspx?scid=kb;en-us;813349 

Use with Programming Languages:  

Unmanaged C++

NO

VB6

NO

Managed Code (.NET)

YES

Can Run Under:

Running Under Windows Service

YES

Running Under IIS

YES

Running Under COM+

YES

Running in a Web Service

YES

Sends Via:

Send Via MAPI Provider

NO

Sending Via SMTP Pickup

YES

Sending Via SMTP Port

YES

Sending Via Submission URL

NO

Can Save Sent Mail in Sent Items folder

NO

Some Points Of Interest:

  • Works with .NET. 
  • Can build complex email.
  • Sending email by SMTP pickup folder is more efficient than sending by SMTP port.  This approach is recommended when sending a lot of email.  
  • System.Net.Mail only supports “Explicit SSL”. 
  • System.Net.Mail has some features which CDOSYS does not, however it does not fully replace the capabilities which CDOSYS has.  You should evaluate the capabilities of System.Net.Mail and CDOSYS and decide which is best for the application you are writing.
  • Because it is not a wrapper around CDOSYS, it is known to structure MIME messages differently in some cases although they should still conform to the RFC specs.
  • If you get an error back when sending an email then you should capture SmtpFailedRecipientsException exception and handle it.  An example of this is resending an email when a MailboxBusy or MailboxUnavailableis thrown.  See documentatin on SmtpException for more information and a sample on how to write the code.

Homework if you wish to know more:

System.Net.Mail with SSL to authenticate against port 465
https://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx

System.Net.Mail Namespace
https://msdn.microsoft.com/en-us/library/System.Net.Mail(v=vs.110).aspx

MailMessage Class
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage(v=vs.110).aspx

Attachment Class
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment(v=vs.110).aspx

SmtpException Class
https://msdn.microsoft.com/en-us/library/system.net.mail.smtpexception(v=vs.110).aspx

Howto: Add a body part using System.Net.Mail
https://blogs.msdn.com/b/webdav_101/archive/2008/07/16/howto-add-a-body-part-using-system-net-mail.aspx

Example of setting headers with System.Net.Mail
https://blogs.msdn.com/b/webdav_101/archive/2008/07/16/example-of-setting-headers-with-system-net-mail.aspx

Adding Inline Attachments with CDOSYS and System.Net.Mail.
https://blogs.msdn.com/b/webdav_101/archive/2008/07/31/adding-inline-attachments-with-cdosy-and-system-net-mail.aspx

Enumerating fields for CDOSYS, System.Web.Mail and System.Net.Mail
https://blogs.msdn.com/b/webdav_101/archive/2008/08/14/enumerating-fields-for-cdosys-system-web-mail-and-system-net-mail.aspx

Large samples:

NetMail Sender Tool using System.Net.Mail
https://netmailsender.codeplex.com/

Also see:

About: SMTP Sending APIs
https://blogs.msdn.com/b/webdav_101/archive/2015/05/28/about-smtp-sending-apis.aspx

About: Messaging APIs
https://blogs.msdn.com/b/webdav_101/archive/2015/08/07/about-messaging-apis.aspx