I am trying to implement automatic email functionality for a website I developed. On initial basis I tested email code with Gmail credentials and it worked fine. Below is the code which is working fine.
public static int SendEmail(string from, string to, string subject, string body)
{
int result = 0;
MailMessage msg = new MailMessage();
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("MyEmailID@gmail.com", "MyGmailPassword");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
mail = new MailMessage();
try
{
mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);
mail.To.Add(to);
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = body;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.ReplyToList.Add("MyEmailID@gmail.com");
SmtpServer.Send(mail);
result = 1;
}
catch (Exception ex)
{
result = 2;
}
return result;
}
When I used client's email settings with above code, it is not working. Client has provided me with below information.
Official EmailID/Password: Two different email address and their passwords
SMTP:
Outgoing Server: Two different server for SSL and NON SSL settings
SMTP PORT: 587 and 465
I tried all the possible combination of email/password, SMTP port..etc but none is working.
I am getting two kinds of error with these combinations...
err 1: System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
err 2: The operation has timed out.
But I am able to login on webmail with the credentials provided, so I guess both the emailIDs, and their respective passwords are correct.
Any help would be appreciated.
Thanks and regards,
Sam