问题
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