Jebin Dhanush

Jebin Dhanush

  • NA
  • 40
  • 6k

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("[email protected]");
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)