title: Set up Nodemailer to secure email with a STARTLS handshake?
body: <p>I need to send e-mail through my remote Postfix/Dovecot SASL service from Node.js on my desktop. </p>
  
  <p>When I send email using Thunderbird, it works and the Postfix server logs show</p>
  
  <p><code>Anonymous TLS connection established from unknown[dh.cp.ip.ip]: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)</code></p>
  
  <p>But not through nodemailer, where the Postfix server logs:   </p>
  
  <pre><code>Nov 26 22:02:31 servicelabel postfix/submission/smtpd[27019]: connect from unknown[dh.cp.ip.ip]                                                         
  Nov 26 22:02:31 servicelabel postfix/submission/smtpd[27019]: lost connection after CONNECT from unknown[dh.cp.ip.ip]                                   
  Nov 26 22:02:31 servicelabel postfix/submission/smtpd[27019]: disconnect from unknown[dh.cp.ip.ip] commands=0/0        
  </code></pre>
  
  <p>These same settings are used for Nodemailer transport and Thunderbird</p>
  
  <pre><code>  let transporter = nodemailer.createTransport(
      {
          host: "mx.example.com",
          port: 587,
          secure: false, // use TLS
          // requireTLS:true,        
          auth: {
              user: "emailuser",
              pass: "password"
          },
          tls: { rejectUnauthorized: false },
          // logger: true,
           debug: true 
      },
      {      
          from: 'myuser@example.com',
      }
  );
  </code></pre>
  
  <p>But Nodemailer won't connect to Dovecot with TLS the same way Thunderbird does ?? </p>
  
  <p>when I change secure to <code>true</code> to force TLS a <code>SSL routines:ssl3_get_record:wrong version number</code> error (below); it appears when verifying the transport. </p>
  
  <pre><code>transporter.verify(function(error, success) {
    if (error) {
      console.log(error);
    } else {
      console.log("Server is ready to take our messages");
      return false;
    }
  });
  </code></pre>
  
  <pre><code>Error: 140185182082944:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
  code:"ECONNECTION"
  command:"CONN"
  function:"ssl3_get_record"
  library:"SSL routines"
  message:"140185182082944:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n"
  reason:"wrong version number"
  stack:"Error: 140185182082944:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n"
  </code></pre>
  
  <p>When I test with this command: </p>
  
  <p><code>openssl s_client -starttls smtp -connect  mx.example.com:587</code></p>
  
  <pre><code>depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
  verify return:1
  depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
  verify return:1
  depth=0 CN = mx.example.com
  verify return:1
  ---
  Certificate chain
   0 s:CN = mx. ...
  ...
  ...
  </code></pre>
  
  <p>... the SSL/STARTTLS handshake succeeds and certificates </p>
  
  <p>But if I use this command:</p>
  
  <p><code>openssl s_client -connect mx.example.com:587 -crlf -ign_eof</code></p>
  
  <p>I get the same error as with Nodemailer</p>
  
  <p><code>CONNECTED(00000005)
  140508975112640:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../ssl/record/ssl3_record.c:332:</code></p>
  
  <p>I've tried a number of option configurations and am at a loss... </p>
  
  <p>How do I send secure email through my Dovecot/Postfix server via Nodemailer? Do I need to configure some certs in Nodemailer? Should I use something different to send secure email from node.js?  Any help appreciated. </p>