Trying to send email using smtp-relay.gmail.com and Nodemailer. Error ssl3_get_record:wrong version number

房东的猫 提交于 2020-11-29 23:52:39

问题


Trying to send email with G Suite smtp-relay using Nodemailer.

const transporter = nodemailer.createTransport({
  host: "smtp-relay.gmail.com",
  port: 587,
  secure: true,
  auth: {
    user: "username@mydomain.com",
    pass: "password"
  }
});

const result = await transporter.sendMail({
  from: `'"JOHN" <john@externaldomain.com>'`,
  to: "hello@mydomain.com",
  subject: "Hello",
  text: "Hello world!",
});

This is what G Suite says about using TLS: Link1 Link2

This is what Nodemailer says: Link

CONTINUE

Basically G Suite tells me that I should use port 587 for TLS, and Nodemailer says I shouldn't.

Don't know if it has something to do with the ports, but this is the error I'm getting:

NOTE: I'm trying on port 587.

{ [Error: 13252:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332: ] code: 'ESOCKET', command: 'CONN' }

If I change to port 465, I get this error:

'535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials ', responseCode: 535, command: 'AUTH PLAIN' }

I know my user and pass are correct.

What am I doing wrong?


回答1:


Basically G Suite tells me that I should use port 587 for TLS, and Nodemailer says I shouldn't.

Both talk about different things. The first one (G Suite) talks about SSL vs. TLS, i.e. compares various versions of the protocol. The second one (Nodemailer) talks about explicit vs. implicit TLS, i.e. explicitly upgrading a plain connection using the STARTTLS command (port 25 and 587) or establishing TLS directly after the TCP connect (port 465).

Thus, follow the recommendation from Nodemailer to set secure: false. If you want to enforce use of TLS, i.e. fail if STARTTLS is not supported by the mail server, then set requireTLS: true as documented.



来源:https://stackoverflow.com/questions/62375786/trying-to-send-email-using-smtp-relay-gmail-com-and-nodemailer-error-ssl3-get-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!