.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

error in smtp sending mail reg

Posted By: Gowthammanju     Posted Date: May 18, 2011    Points:5   Category :ASP.Net
i used following code to send mail from asp.net pages

these are

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
{ }
protected void Button1_Click(object sender, EventArgs e)
Response.Write(SendMail("info@letrouters.com", "info@letrouters.com", "info@letrouters.com", "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;
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
if (ccList != null && ccList != string.Empty)
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("info@letrouters.com", "xxxxx");

msg = "Successful";
catch (Exception ex)

return msg;

but i am getting error such as
failure in sending mail at line (smtpClient.Send(message);)

i am trying to send message to my companymail id using asp.net can any one guide me and help me to come out of this problem

Author: Gowthammanju             
Posted Date: May 19, 2011     Points: 20   

go through following links


or try this approach

plz note, if you where working with your own domain (email) other than yahoo, gmail etc then you should have running smtp details, to check this by configuring smtp with outlook express, if you success here then come to coding.

find the sample code working for me (i'm using gmail here):-

public void sendmail(string abc, string xxx, string abx)
//constructing html based email
string smsg = "Your email content here:<br>";
smsg += "<br><b>Test: </b>" + abc;
smsg += "<br><b>Test: </b>" + xxx;
smsg += "<br><b>Test: </b>" + abx;
smsg += "<br><br><br><br>";
smsg += "<b>Test</b>";

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("receiver-email-id")); //you may find this from db too
message.From = new MailAddress("yourname@gmail.com");

message.Subject = "Your Subject";
message.Body = smsg;
message.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.Port = 587; //Gmail works on port 587 for me
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("yourname@gmail.com", "password");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = nc;
//place the catch statements here

Now call this function as

sendmail(a.Text, b.Text, c.Text);

Thanks & Regards,

Mark if the answer is true
Author: Gowthammanju             
Posted Date: May 19, 2011     Points: 20   

means, there is something problem with smtp settings, plz reply which email server you are using. gmail, yahoo or your own website mail address.

Look at this article to configure outlook (so that you can check your smtp, if works with outlook then will with asp):-


Thanks & Regards,

Mark if the answer is true
Author: shiv chandra             
Posted Date: June 08, 2011     Points: 20   

Please check SMTP Port and credential.


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend