2
votes

Our application has the possibility to send emails via SmtpClient. One of our customer is trying to do so by using his gmail account and it fails resulting in a timeout. However, from our testing lab it works just fine (with another gmail account).

this is the trace we got from our customer

In the trace i can see that the server is not answering with Certificate, Server Key Exchange, Server Hello Done. And im wondering what can be the cause for this?

I also noticed in the traces, the customer is using TLSv1 so I tried to replicate the error on a Windows7 system but still it works for me.

    oSmtp = new SmtpClient(this.host, this.port);
                oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                oSmtp.EnableSsl = ssl;
                NetworkCredential oCredential = new NetworkCredential(this.userName, this.password);
                oSmtp.Credentials = oCredential;
                oSmtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                string userState = null;
                oSmtp.SendAsync(oMsg, userState);

As far as the code goes, enableSsl is true, the port is 587 and we also instructed our customer to check his gmail account and allow less secure applications.

We will ask the customer for more specific details and try to put more traces in our application, but i would like to know if there is anything that can prevent the server to answer with Certificate,...

Inspecting the traces revealed no significant difference between customers Client Hello and our test Client Hello.

Thanks!

1
Please edit your question and include the actual code and stack trace not images. Ask the user if they have 2fa enabled?DaImTo
I will ask about 2fa. I'll try to make a test in our lab, to see if we get a similar resultAlexandra Ramona
Just made a test in the lab, with a gmail account with 2fa and it doesnt even reach the Server Hello part.Alexandra Ramona
In order to use the SMTP server with 2fa enabled on the account you need to create an app password and use that instead of the password itself. SMTP servers cant handle the 2fa call.DaImTo
Im not planning to use smtp with 2fa enabled. I just ran a test with the current application to see how far it goes in the communication with the server if the account has 2fa. Comparing the result, the client doesnt have 2fa enabled.Alexandra Ramona

1 Answers

3
votes

This is a working sample i used few days ago:

            string fromAddress = "[email protected]";
            var toAddress = new MailAddress("[email protected]", "To person");
            const string fromPassword = "pass";
            const string subject = "test";
            const string body = "Hey now!!";

            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(fromAddress);
                mail.To.Add(toAddress);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                //mail.Attachments.Add(new Attachment("C:\\file.zip"));
               
                using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                {
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                    smtp.EnableSsl = true;
                    smtp.Send(mail);
                }
            }

also make sure to enable Less secure app access for the gmail you are using to send data: