Jebin Dhanush

Jebin Dhanush

  • 2k
  • 40
  • 3.9k

Sending mail using asp.net

Nov 13 2018 3:08 AM
Hi ,
 
      I have to send mail using private server. But i receive " Failure sending mail. " error 
 
My code 
 
private static void SendMail()
{
try
{
string SmtpHost = ConfigurationManager.AppSettings["SmtpHost"].ToString();
string SmtpFromMail = ConfigurationManager.AppSettings["SmtpFromMail"].ToString();
string SmtpFromMailPwd = ConfigurationManager.AppSettings["SmtpFromMailPwd"].ToString();
//foreach (DataRow dr in objDataTable.Rows)
//{
MailMessage mail = new MailMessage();
mail.To.Add("jebinjuli24@gmail.com");
mail.From = new MailAddress(SmtpFromMail);
//string EventName = DicEventTypeName[dr["Email"].ToString()];
mail.Subject = "Testing";
mail.Body = "Test";
SmtpClient smtp = new SmtpClient();
smtp.Host = SmtpHost; //Or Your SMTP Server Address
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential(SmtpFromMail, SmtpFromMailPwd); // 
smtp.EnableSsl = true;
smtp.Send(mail);
}catch(Exception e)
{
}
}
 
Could you give any suggestion ?
 
Thanks in advance !!
  
 

Answers (3)