Я создал транспорт для отправки электронной почты следующим образом:
const nodemailer = require('nodemailer');
const transport = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: parseInt(process.env.MAIL_PORT),
auth: {
user: process.env.MAIL_USER,
user: process.env.MAIL_PASS
}
});
со следующими переменными в моем variables.env
файле:
MAIL_USER=def
MAIL_PASS=abc
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
С этим я получаю следующая ошибка:
(node:39148) UnhandledPromiseRejectionWarning: Error: Invalid login: 535 5.7.0 Invalid login or password
[?] at SMTPConnection._formatError (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:555:19)
[?] at SMTPConnection._actionAUTHComplete (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:1244:34)
[?] at SMTPConnection.<anonymous> (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:338:26)
[?] at SMTPConnection._processResponse (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:702:20)
[?] at SMTPConnection._onData (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:507:14)
[?] at TLSSocket.<anonymous> (/Users/JAAI/Desktop/WB Node/Learn-Node/starter-files/node_modules/nodemailer/lib/smtp-connection/index.js:653:51)
[?] at TLSSocket.emit (events.js:210:5)
[?] at addChunk (_stream_readable.js:309:12)
[?] at readableAddChunk (_stream_readable.js:290:11)
[?] at TLSSocket.Readable.push (_stream_readable.js:224:10)
[?] at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23)
[?] (node:39148) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[?] (node:39148) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Я пробовал консоль регистрировать переменные, и они верны.
console.log(process.env.MAIL_HOST) // smtp.mailtrap.io
console.log(parseInt(process.env.MAIL_PORT)) // 2525
console.log(process.env.MAIL_USER) // def
console.log(process.env.MAIL_PASS); // abc
В качестве обходного пути я пробовал это, и он работает:
const transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "def",
pass: "abc"
}
});
Насколько я могу судить, я не вижу разницы. В чем проблема? Спасибо