Click here to Skip to main content
11,721,385 members (82,792 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# C#4.0
My code:

private void button1_Click(object sender, EventArgs e)
              MailMessage mail = new MailMessage();
              mail.From = new MailAddress("");
              mail.Subject = "School Name";
              string Body = txtmsg.Text;
              mail.IsBodyHtml = true;
              SmtpClient smtp = new SmtpClient("localhost", 25);
              smtp.Host = ""; //Or Your SMTP Server Address
              smtp.Credentials = new System.Net.NetworkCredential
                   ("", "rima001");
              smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
              smtp.EnableSsl = true;
              MessageBox.Show("Mail Send");
          catch (Exception ex)

My App.Config :

<?xml version="1.0" encoding="utf-8" ?>
      <smtp deliveryMethod="PickupDirectoryFromIis">
        <network defaultCredentials="true" host="localhost" port="25"/>

Error: Failure sending mail

Can anybody tell me where is the problem for sending mail in windows application ? Please help me.
Posted 29-Jun-12 23:52pm
barneyman at 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 at 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..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Gmail's send port is 587 not 25.
UL UL ALBAB at 30-Jun-12 6:22am
Thank You. This is working...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 254
2 Mika Wendelius 170
3 cyycoish 70
4 ppolymorphe 66
0 Sergey Alexandrovich Kryukov 2,249
1 OriginalGriff 1,024
2 F-ES Sitecore 690
3 Maciej Los 619
4 Richard MacCutchan 580

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 30 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100