Unable to connect to remote server

c#

Solution

You need to set the credentials for Gmail

var client = new SmtpClient("smtp.gmail.com", 587)
 {
    Credentials = new NetworkCredential("myusername@gmail.com", "mypwd"),
    EnableSsl = true
};
client.Send("myusername@gmail.com", "myusername@gmail.com", "test", "testbody");

Problem

I am new to C# and I am trying to send an email from a desktop program I am developing. Here is the code I am using but I keep getting the error below : ``` System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add("thesma@gmail.com"); message.Subject = "This is the Subject line"; message.From = new System.Net.Mail.MailAddress("ideas@gmail.com"); message.Body = "This is the message body"; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com",578); smtp.EnableSsl = true; smtp.Send(message); ``` I can't seem to find out what the problem is...

Original source