How to sent mail in ASP .Net
--use the following namespaces :
using System.Net.Mail;
using System.Net;
**********************************************
--Call the mathod on the button click :
SendMail();
***********************************************
--defination of the method :
private void SendMail() //string body, string msgto, string msgfrom, string sub, string cpcc)
{
System.Text.StringBuilder msg = new System.Text.StringBuilder();
msg.Append("<table style='font-family:Calibri'>");
msg.Append("<tr><td align='left'>Dear " + txtFirstName.Text + ",<br/></td></tr>");
msg.Append("<tr><td><p>you have been successfully registered.</p></td></tr><br/>");
msg.Append("<tr><td><p>Login Details:</p></td></tr><br/>");
msg.Append("<tr><td><p>User Id: " + txtMobileNumber.Text + " and Password: " + txtPassword.Text + "</p></td></tr><br/>");
msg.Append("<tr><td><p>Thanks & Regards,</p></td></tr>");
msg.Append("<tr><td><p>CommSoft E-Services Pvt. Ltd.</p></td></tr>");
msg.Append("</table>");
string To = txtEmail.Text;
string From = "no-reply";
string Subject = "*** Confirmation Registration ***";
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
MailMessage message = new MailMessage();
//message.CC.Add(new MailAddress(cc));
message.Body = Convert.ToString(msg);
message.IsBodyHtml = true;
message.To.Add(To);
message.From = new MailAddress(From);
message.Subject = Subject;
message.Priority = MailPriority.High;
SmtpClient SmtpMail = new SmtpClient();
{
SmtpMail.Host = "smtp.gmail.com";
SmtpMail.Port = 4543;
SmtpMail.EnableSsl = true;
SmtpMail.UseDefaultCredentials = true;
SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpMail.Credentials = new System.Net.NetworkCredential("no-reply", "4545345");
SmtpMail.Send(message);
}
message.Attachments.Dispose();
}
}
}
No comments:
Post a Comment