This project is read-only.

SMTP - The handshake failed due to an unexpected packet format.

Dec 8, 2013 at 8:45 PM
Edited Dec 8, 2013 at 8:47 PM
i'm trying to send an email via but i keep getting
The handshake failed due to an unexpected packet format.
            //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
            SmtpClient client = new SmtpClient();

            client.ServerName = "";
            client.Port = 587;
            client.UserName = "";
            client.Password = "xxxxx";

            client.RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
            client.Ssl = true;

            SmtpMessage mail = new SmtpMessage();
            string From = "";
            mail.From = new HigLabo.Net.Mail.MailAddress(From);
            mail.To.Add(new HigLabo.Net.Mail.MailAddress(""));
            mail.Subject = "xxxxx";
            mail.BodyText = "xxxxx<br>xxxxx!";
            mail.IsHtml = true;

            client.AuthenticateMode = SmtpAuthenticateMode.Auto;
            string laststat = "";
            if (client.Authenticate())
                Console.WriteLine("Sending Email...");
                var rs = client.SendMail(mail);

                if (rs.SendSuccessful == true)
                    laststat = "success";
                    laststat = rs.State;
                laststat = client.State;

i'd really appreciate if anyone that can point me to the right direction !

PS: after some digging around i heard that in order for the smtp request to go through we need to send these commands in order :
  1. Connect
  2. HELO - will not accept the STARTTLS until this has been sent
  3. STARTTLS - apparently this sets up the server to accept an encrypted connection
Dec 9, 2013 at 1:54 AM

What is your "an unexpected packet format"?
Can you describe more detail?
What Exception raise when you execute your code?

Dec 9, 2013 at 12:35 PM
this is the whole exeption i was getting
System.IO.IOException was unhandled
  Message=The handshake failed due to an unexpected packet format.
       at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
       at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
       at HigLabo.Net.SocketClient.Connect() in C:\Users\HP\Documents\Visual Studio 2010\Projects\higlabo-105132\HigLaboNet\HigLabo.Net\Socket\SocketClient.Net4.cs:line 274
       at HigLabo.Net.Smtp.SmtpClient.Open() in C:\Users\HP\Documents\Visual Studio 2010\Projects\higlabo-105132\HigLaboNet\HigLabo.Mail\Smtp\SmtpClient.cs:line 127
       at Sendemail.Program.Main(String[] args) in C:\Users\HP\Documents\Visual Studio 2010\Projects\Sendemail\Sendemail\Program.cs:line 65
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
Its failing on Ssl.AuthenticateAsClient() verification
i'm guessing this is because a HELO command is not sent and the handshake failed because requires this command to be executed before the STARTTLS command
Dec 10, 2013 at 6:40 AM
There are two way sending mail by secure connection.
One is SSL, second is TLS.

Please try to set Tls property to true and Ssl property to false.

Dec 11, 2013 at 4:59 PM
Edited Dec 11, 2013 at 5:02 PM
Both doesn't work with and smtp servers :(
tried all smtp hosts and all smtp ports with switching between tls and ssl , but no luck !

can you add support to hotmail and outlook servers ??
Dec 12, 2013 at 12:18 AM

I can add support for hotmail,outlook support.
Perhaps, hotmail & Certificate may be something wrong.

I can send a mail from by below code without Certificate.
        var cl = new SmtpClient("", 587, "", "xxxxx");
        cl.Tls = true;
        cl.Ssl = false;
        SmtpMessage mg = new SmtpMessage();
        mg.From = new MailAddress("");
        mg.To.Add(new MailAddress(""));
        mg.Subject = "Hotmail Live mail";
        mg.BodyText = "This is a mail from hotmail smtp server!";
        var text = mg.GetDataText();

        var result = cl.SendMail(mg);

Can you send a mail without Certificate from
Dec 12, 2013 at 11:27 AM
wow , thanks so much , that did the trick :D
Jan 7, 2014 at 2:05 AM
Hi Aymen99.
I modify that trick by adding EncryptedCommunication property to SmtpClient object.
If you use TLS
cl.EncryptedCommunication = SmtpEncryptedCommunication.Tls;
When Ssl
cl.EncryptedCommunication = SmtpEncryptedCommunication.Ssl;

More intuitive for developer.

Thank you for your comment.
That make me this idea.