views:

2123

answers:

3

Ok, I have been using the following script for over a year now to send email (via gmail) from my host, and it has worked just fine (the Settings.Get() just return strings):

public class Email : SmtpClient
{
    public MailMessage Message { get; private set; }

    public Email(string to, string from, string subject, string body) : base(Settings.Get("smtp"), 25)
    {
        this.EnableSsl = Convert.ToBoolean(Settings.Get("ssl"));
        if(this.EnableSsl)
            this.Credentials = new System.Net.NetworkCredential(Settings.Get("gm"), Settings.Get("gmp"));
        this.Message = new MailMessage(from, to, subject, body);
    }

    public void Send()
    {
        try { this.Send(Message); }
        catch (Exception ex) { throw ex; }
    }
}

But, since yesterday, I have been getting this error:

Error: Server does not support secure connections.

Now of course my host thinks it's not their fault, BUT I DIDN'T CHANGE ANYTHING. Also, it still works fine on my local and test machines. Any idea what might be causing this so I can tell them to fix it?

Thank you... this is driving me nuts!

A: 

check your event log, maybe the handshake beetwen the your pc and the server is not working.or the certificate is not being downloaded or it may contain errors wich may be something weird comming from gmail

Oscar Cabrero
+1  A: 

What SMTP-Server and port are you using? You will need to use port 465 or 587 if you are connecting directly to smtp.gmail.com to send ssl mail.

It looks like you are using port 25, are you sure that your Settings.Get("ssl") returns false?

Read here for details.

Espo
very strange, I have been using port 25 for at least 2 years, and has never given me a problem until yesterday... (I switched to 587)
naspinski
A: 

Specifying the port to use 587 has also solved that problem for me -

Error: Server does not support secure connections.

The company I for work created a windows service that does some stuff and then sends an email from gmail. In the beginning it sent the email just fine with no problems. After installing the service on a Vista machine we noticed it would not send the email. Then the same thing once we installed it on windows 2008 server. We've even start to notice it a small number of XP machines. Once we changed the port to 587 it started to work fine again and send the emails.

Here is some sample code that has worked on all machines we have tried (XP, Vista, Server 2008).

        Dim client As New Net.Mail.SmtpClient("smtp.gmail.com")
        client.Port = 587
        client.EnableSsl = True
        client.UseDefaultCredentials = False
        client.Credentials = loginInfo
        client.Send(mm)
jacook11