Wednesday, July 28, 2010

Send Email in Asp.net .. System.Web.Mail

 We can easily sent emails from asp.net using Mail Message which comes under name-space System.Web.Mail.

The Code is as Follows...



using System.Web.Mail;

 MailMessage messa = new MailMessage();
       messa.From = "martinkabraham.gmail.com";
       messa.To = "martinkabraham@gmail.com";
       messa.Subject = "Test Mail";

       messa.BodyFormat = MailFormat.Html;
       messa.Body = "Hai all";

       SmtpMail.SmtpServer = "";
       SmtpMail.Send(messa);


If Smtp throws exception then replace  SmtpMail.SmtpServer = ""; to  SmtpMail.SmtpServer = "localhost";

No comments:

Post a Comment