0
votes

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:

  1. 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.

  2. 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.

1
what error message do you get?user1666620
it shows different messege 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 port465: Operation timed outAnup Raj
Are you sure your domain (smtp.yourdomain.com) handles your email? If for example you use Google Apps or any other third party sw to handle your email, the smtp configuration may be different.Rafael Leites Luchese

1 Answers

1
votes

Go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps.