1

my code:

private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential("mymail@gmail.com", "mypassword");
            client.EnableSsl = true;

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("mymail@gmail.com", "SMTP Test");
            mail.To.Add(new MailAddress("mymail@gmail.com"));
            mail.Subject = "Subject test";
            mail.Body = "Body test";
            client.Send(mail);
            MessageBox.Show("mail send.");
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

I get this error:

I cant upload images yet so i use puush.

http://puu.sh/fpAnF/d4372b0b55.png

Error a bit translated:

Error when sending e-mail. system.net.mail.smtpexception: error when sending e-mail. ---> system.net.webexception: can't connect to the external server ---> system.net.sockets.sochetexception: can't connect because the goalcomputer (dont know the exact translation of that) the connection actively has refused.

can somobody please help me?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
ferdi0314
  • 25
  • 6
  • Here, have a look at: http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp. Works for me – Tomer Klein Feb 03 '15 at 09:28
  • @TomerKlein doesn't work for me :( – ferdi0314 Feb 03 '15 at 09:31
  • try running this command: telnet smtp.gmail.com 587 from CMD window. and let me know the result – Tomer Klein Feb 03 '15 at 09:35
  • @TomerKlein http://puu.sh/fpBMx/305f30cc11.png translated: telnet isn't recognized as an internal, or external command, program or bachfile. – ferdi0314 Feb 03 '15 at 09:38
  • if you are working with windows 7 or 8 you have to install telnet client From add/remove windows features. you can try connect to your account using outlook, it will help you to understand is the problem is in your code, – Tomer Klein Feb 03 '15 at 09:40
  • @TomerKlein My colleague solved it. I tried another port. Thank you for your help. Appreciate it. – ferdi0314 Feb 03 '15 at 09:42

0 Answers0