SMTPs with GMail

Jul 15, 2010 at 6:18 PM

Hello,

I tried to send a simple mail without attachment by gmail server.

But it does'nt work.

I tried to send it by port 485 with SSL, and by port 587 with TLS but no one is working.

Can you give me a valid source code to send a simple mail with a gmail account.

Thanks,

Victor

Coordinator
Jul 16, 2010 at 4:16 PM

It seems port no is wrong.Port no is 465.
Here is a complete code work with GMail ssl.

   SmtpClient cl = new SmtpClient();
   cl.ServerName = "smtp.gmail.com";
   cl.Port = 465;
   cl.Ssl = true;
   cl.AuthenticateMode = SmtpAuthenticateMode.Auto;
   cl.UserName = "youraddress@gmail.com";
   cl.Password = "yourPassword";
   SmtpMessage mg = new SmtpMessage();
   mg.From = "youraddress@company.com";
   mg.To.Add(new MailAddress("youraddress@company.com"));
   mg.Subject = "GMail test";
   mg.BodyText = "GMail test body";
   var rs = cl.SendMail("<youraddress@company.com>", "<youraddress@gmail.com>", "", "", mg.GetDataText());

regard.