0

I have a problem in this code i am new please help me

Error is : Failure sending mail.

Inner Exception is : Unable to connect to the remote server.

Here is my code:

    try
{
    MailMessage message = new MailMessage();
    SmtpClient smtp = new SmtpClient();
    message.To.Add(emaild_id);
    message.From = new MailAddress(my_email_id);
    message.Subject = "Info";
    message.Body = "something.....";
    smtp.Port = 587;
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential(strFromMail, strPassword);
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Send(message);
    MessageBox.Show("Mail has been sent successfully.");
}
catch (Exception ErrMessage)
{
            MessageBox.Show(ErrMessage.Message, "ASCEND", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
Bhuvana S
  • 1
  • 1

1 Answers1

0

Try using Port number 465 instead of 587