0

i created a window app which send email to a particular email id which is inserted in my textbox,

here is my code on my button click

 private void button1_Click(object sender, EventArgs e)
        {
            MailMessage msg = new MailMessage("sender@gmail.com", textBox1.Text, "here is the subject of the mail", textBox2.Text);
            SmtpClient mail = new SmtpClient();
            mail.Host = "smtp.gmail.com";
            mail.Port = 465;
            mail.Credentials = new NetworkCredential("sender@gmail.com", "senderpassword");
            mail.EnableSsl = true;
            mail.Send(msg);
            MessageBox.Show("message has been sent to the mail provided");

        }

i am getting an error message which is written below

'System.Net.Mail.SmtpException' occurred in System.dll

please let me know what is the issue which i am facing

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Have you *checked* GMail's documentation for the correct settings? GMail doesn't use port 465. In any case, you should post the *full* exception, not only the message. – Panagiotis Kanavos Feb 14 '17 at 12:12
  • try using 587 port – NicoRiff Feb 14 '17 at 12:13
  • Furthermore, there are dozens of similar SO questions, that include links to GMail's documentation and explain what is required, eg when you need an authorization key and how to bypass it – Panagiotis Kanavos Feb 14 '17 at 12:14
  • Also check [this duplicate](http://stackoverflow.com/questions/757987/send-email-via-c-sharp-through-google-apps-account). The top answer shows how you can specify the server settings in the application's configuration. Note that you can add the `enableSsl="true"` attribute in the config file as well – Panagiotis Kanavos Feb 14 '17 at 12:17

0 Answers0