Gowtham manju

Gowtham manju

  • NA
  • 188
  • 78.7k

error in smtp sending mail reg

May 18 2011 5:49 AM
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(SendMail("[email protected]", "[email protected]", "[email protected]", "Test Mail", "Test Mail Body"));
}
public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.letrouters.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
  smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxx");  

smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

return msg;
}


Answers (21)