Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
My code:

C#
private void button1_Click(object sender, EventArgs e)
      {

          try
          {
              MailMessage mail = new MailMessage();
              mail.To.Add("shi01715@gmail.com");
              mail.To.Add(txtto.Text.ToString());
              mail.From = new MailAddress("shishir64092@gmail.com");
              mail.Subject = "School Name";
              string Body = txtmsg.Text;
              mail.IsBodyHtml = true;

              SmtpClient smtp = new SmtpClient("localhost", 25);
              smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
              smtp.Credentials = new System.Net.NetworkCredential
                   ("shishir64092@gmail.com", "rima001");
              smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
              smtp.EnableSsl = true;
              smtp.Send(mail);
              MessageBox.Show("Mail Send");
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }


My App.Config :

XML
<?xml version="1.0" encoding="utf-8" ?>

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="PickupDirectoryFromIis">
        <network defaultCredentials="true" host="localhost" port="25"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>


Error: Failure sending mail

Can anybody tell me where is the problem for sending mail in windows application ? Please help me.
Posted
Comments
barneyman 30-Jun-12 6:18am    
i do hope you haven't just handed the world your gmail password! I'd change it pretty quick
Dhinesh kumar.V 31-Oct-12 2:59am    
Hi All,

Is there any possibility for send mail from any other ID like yahoo,hotmail.. I had done for gmail for long ago but dont know for other id... all replies welcome..

Gmail's send port is 587 not 25.
 
Share this answer
 
Comments
UL UL ALBAB 30-Jun-12 6:22am    
Thank You. This is working...
 
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