sunitc's WebLog

System.Web.Mail

It has been a long time since I have written a component that sends email.  In the .NET world, sending email has been made very easy and all the objects are defind under the System.Web.Mail namespace.  System.Web.Mail is a simple wrapper for the COM objects in cdonts.dll and cdosys.dll.

Following is a code snipped for sending email with an attachment:

   MailMessage MailMsg= new MailMessage();
   MailMsg.To = "
sunitc@microsoft.com";
   MailMsg.From = "
SWM_Test@sunitc.com";
   MailMsg.Subject = "[info] System.Wed.Mail Test Message";
   MailMsg.Body = "System.Web.Mail Body of the Message";
   // Create the attachment : enter the correct path to the file that is to be attached
   MailAttachment attachment = new MailAttachment("mypath\test.txt"); //create the attachment
   MailMsg.Attachments.Add( attachment );
   // Put in your real smtp server below
   SmtpMail.SmtpServer = "mySmtpServer";
   SmtpMail.Send( MailMsg);

Published Monday, May 31, 2004 2:11 PM by sunitc

Comments

 

Vinit Carpenter said:

Finally!! Another blog entry :)
May 31, 2004 2:49 PM
 

David said:

You could also find this on MSDN!
May 31, 2004 5:05 PM
 

Robert W. McLaws said:

What the namespace is missing is a way to create in-memory attachments that don't first reside in the file system.
May 31, 2004 7:48 PM
 

Huobazi said:

You could also find this in DotText Source Code.
May 31, 2004 9:01 PM
 

Anon said:


It would have been nice however if that component told you what went wrong when an error occurred. Throwing an exception with the message 'in there somewhere' is problematic.
June 1, 2004 3:10 AM
 

Tiernan OTooles Programming Blog said:

June 1, 2004 4:12 AM
 

Mark Bell said:

It would also have been nice if the component supported authentication; as it is now I basically can't use it because all the mail accounts I use require authentication on the SMTP server and there is no way to send the credentials using SmtpMail.

If anyone knows of a good solution, please let me know!
June 1, 2004 4:25 AM
 

David Dehghan said:

Yes sending mail is amazingly simple. Here is a good resource on System.web.mail
http://systemwebmail.com/
June 1, 2004 5:39 AM
 

Matt said:

June 1, 2004 11:02 AM
 

Brian Schkerke said:

I second the authorization issue. There are plenty of free components available that allow this but in a world where we fight spam daily -- shouldn't authentication be required?
June 1, 2004 2:26 PM
 

Satish said:

Is there a way the sender can choose a template for the mail being sent .I need to have different mail templates
June 11, 2004 9:25 AM
 

dianying xia zai said:

July 26, 2004 3:35 AM
Anonymous comments are disabled

This Blog

Syndication

Tags

No tags have been created or used yet.

Archives


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker