Send Email in DotNet 3.5

Thursday, December 17, 2009






There two ways to Send Email in Dotnet
1 System.Web.Mail (Dotnet FrameWork 2.0 )
its now obsoleted in FrameWork 3.5


2. System.Net.Mail

to send Mail in 3.5 here Code

define this code or use myclass dotnet NewMail

// Instantiate a new instance of
MailMessage MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to));
// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{ // Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc)); }
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
// Set the CC address of the mail message
mMailMessage.CC.Add(new MailAddress(cc));
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body; // Secify the format of the body as HTML
mMailMessage.IsBodyHtml = true; // Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal; // Instantiate a new instance of
SmtpClient SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message
mSmtpClient.Send(mMailMessage);


// Instantiate a new instance of

MailMessage MailMessage mMailMessage = new MailMessage();

// Set the sender address of the mail message

mMailMessage.From = new MailAddress(from);

// Set the recepient address of the mail message

mMailMessage.To.Add(new MailAddress(to));

// Check if the bcc value is null or an empty string

if ((bcc != null) && (bcc != string.Empty))

{ // Set the Bcc address of the mail message

mMailMessage.Bcc.Add(new MailAddress(bcc)); }

// Check if the cc value is null or an empty value

if ((cc != null) && (cc != string.Empty))

{

// Set the CC address of the mail message

mMailMessage.CC.Add(new MailAddress(cc));

} // Set the subject of the mail message

mMailMessage.Subject = subject;

// Set the body of the mail message

mMailMessage.Body = body; // Secify the format of the body as HTML

mMailMessage.IsBodyHtml = true; // Set the priority of the mail message to normal

mMailMessage.Priority = MailPriority.Normal; // Instantiate a new instance of

SmtpClient SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message

mSmtpClient.Send(mMailMessage);


Or Define this code in your Web.config file

 



share this post
Share to Facebook Share to Twitter Share to Google+ Share to Stumble Upon Share to Evernote Share to Blogger Share to Email Share to Yahoo Messenger More...

0 comments: