Click here to Skip to main content
15,994,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send mail but showing error where I did mistake

Label1.Visible = true;
        MailMessage mm = new MailMessage();
        SmtpClient smtp = new SmtpClient();
        mm.From = new MailAddress(fromtext.Text);
        mm.To.Add(new MailAddress(totext.Text));
        mm.Subject = txtsubject.Text;
        mm.Body = txtmessage.Text;
        mm.IsBodyHtml = true;
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
        NetworkCred.UserName = "nagaswarupa@brihaspathi.com";//write your gmail user name      
        NetworkCred.Password = "";// write pass word          
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587; //Gmail port for e-mail 465 or 587      
        smtp.Send(mm);
        Label1.Text = "succecc fully send";

smtp.Send(mm);showing error here like Failure sending mail.
Posted
Updated 20-Jan-11 17:50pm
v2
Comments
TejuKrishna 20-Jan-11 23:38pm    
try using defaukt port i.e.25
Rupa1 20-Jan-11 23:48pm    
Label1.Visible = true;
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(fromtext.Text);
mm.To.Add(new MailAddress(totext.Text));
mm.Subject = txtsubject.Text;
mm.Body = txtmessage.Text;
mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "nagaswarupa@brihaspathi.com";//write your gmail user name
NetworkCred.Password = "";// write pass word
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 25; //Gmail port for e-mail 465 or 587
smtp.Send(mm);
Label1.Text = "succecc fully send";

again same error like Failure sending mail.
m@dhu 20-Jan-11 23:51pm    
Edited for code block, readability.
Rupa1 20-Jan-11 23:59pm    
where i am doing mistake sir............

1 solution

I guess, we already shared our views on the same.

It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="587" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>


You need to troubleshoot and check what is the reason n your case.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900