So, I am working on windows Forms and trying so send email with smtp. Here is a Code:
MailMessage mail = new MailMessage(from, to, subject, text);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 465;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(from, password);
try
{
client.Send(mail);
MessageBox.Show("Mesage has benn sant");
}
catch (Exception ex)
{
MessageBox.Show("Failure while sending message");
MessageBox.Show(ex.Message);
}
When I run this Code I am getting Following Error:
"Failure sending email".
When I changed port to 587 I have got following:
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication REquired".
So why I cannot send email ? Can someone explain me that ?
I have changed port to 25 and have sent mail from hotmail( I have replaced "smtp.gmail.com" with "smtp.live.com"), not from gmail. And it works. Seems it's something wrong with gmail.