I'm trying to send mail using SMTPClient in C#.
Everything was fine when I was sending mail using my Gmail account
using HOSTNAME: smtp.gmail.com
and PORT NUMBER: 587
.
Here is the code which I used:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com",587)
//mail
mail.From = new MailAddress("[email protected]","myself");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail C#";
mail.Body = "Hello";
mail.IsBodyHtml = true;
//smtpclient
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
Boolean MailSent=true;
try
{
SmtpServer.Send(mail);
}
catch (SmtpException ex)
{
MessageBox.Show(ex.Message);
MailSent = false;
}
finally
{
if (MailSent == true)
MessageBox.Show("mail sent");
else
MessageBox.Show("Failed to send mail");
}
Here are the details provided by the hosting service provider:
Secure SSL/TLS Settings (Recommended)
Username: [email protected]
Password: Use the email account’s password.
Incoming Server: mocha7004.mochahost.com
IMAP Port: 993
POP3 Port: 995 Outgoing Server: mocha7004.mochahost.com
SMTP Port: 465
Authentication is required for IMAP, POP3, and SMTP.Non-SSL Settings (This is NOT recommended.)
Username: [email protected]
Password: Use the email account’s password.
Incoming Server: mail.opastonline.com
IMAP Port: 143
POP3 Port: 110
Outgoing Server: mail.opastonline.com
SMTP Port: 25 --> When raised a ticket they also suggested me to use 2525 or 25
Authentication is required for IMAP, POP3, and SMTP.
But when I replace them using the details provided by my host provider, I am unable to push the mail.
It shows different error messages when I change port numbers (which I was given by the provider):
- port 25: The remote certificate is invalid according to the validation procedure.
- port 2525: Failure Sending Mail
- port 465: Operation timed out
I cross checked every possible thing, but seems I am lost somewhere.