How to use openssl to send emails?

Sure, you can use an email client such as outlook to send emails, but openssl can help you debug the problems when you set up/configure your own email system.

After issuing the following command,


You can see the ssl(tls) handshake process. The last line of output is:


You are expected to input commands, which will be sent to the email server.

The first command can be HELO or EHLO. EHLO is the advanced version of HELO. When the server receives the EHLO command, it will return a list of commands back so you can know what commands you can use in the following session.

If your server requires authentication, you should use the “auth” command to upload the credentials. According to the server’s configuration, there would be several authentication methods. For example, your server may support the “PLAIN” authentication option. Then you should issue the following command to complete the authentication:


The string xxxxxxx is the base64 code of “username\0\username\0password”. You can get the encoded string using this command:


The following commands would be:


The two commands form the “from” and “to” fields of the sending email. Then you can type the “data” command, and input the content of the email. After inputting all the content, you should type a “.” and a CRLF, then the email will be sent to the server. Input “quit” command to quit openssl.

In using openssl to send emails, I encountered the following problem: openssl quits automatically after the ssl handshaking. The message shows there is a certification verification error (because the server uses a self-signed certification). I searched a lot for how to ignore the certification verification error but got no answer.  All the parameters seem no help to bypass the certification verification. In fact, openssl will continue even the certification verification is failed. The quit of openssl is not caused by the certification verification but the failure of user authentication.


Posted in tips of hosting