Mail sending in asp.net


using System.Net.Mail;
protected void Mailsend()
{
string Message = "";
try
{
//email setup
string smtpHost = "";
string smtpPort = "";
MailMessage ObjMail = new MailMessage();
SmtpClient ObjSmtpClient = new SmtpClient();
System.Net.NetworkCredential BasicAuthenticationInfo = new System.Net.NetworkCredential();


//Mail settings
ObjMail.From = new MailAddress("from@sample.com");
ObjMail.To.Add("Recever@sample.com");
ObjMail.Subject = "sample";
Message = "sample";
ObjMail.Body = Message;
ObjMail.IsBodyHtml = true;

//SMTP settings
smtpHost = System.Configuration.ConfigurationSettings.AppSettings["smtpHost"].ToString();
smtpPort = System.Configuration.ConfigurationSettings.AppSettings["smtpPort"].ToString();
ObjSmtpClient = new SmtpClient(smtpHost, Convert.ToInt16(smtpPort));
ObjSmtpClient.UseDefaultCredentials = false;
BasicAuthenticationInfo = new System.Net.NetworkCredential("", "");
ObjSmtpClient.Credentials = BasicAuthenticationInfo;
ObjSmtpClient.Send(ObjMail);


}
}
catch
{

}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: