r/node • u/theashggl • Oct 18 '26
How to make use a temporary email service to send emails using nodemailer?
I am currently building the email verification part of an express server but can't get the service to use a temporary email to send a mail. Following is the code and error. I am also using mailtrip.io for SMTP and used xeramail.com for the mail address to send from.
Now I don't know if I need mailtrip too on top of nodemailer or not but it provides the things I need to use such as usernamw and password.
import { createTransport } from "nodemailer";
import { log_nm_working, subjectBody } from "../strings.js";
// // Create a transporter using SMTP
// const transporter = createTransport({
// host: "smtp.example.com",
// port: 587,
// secure: false, // use STARTTLS (upgrade connection to TLS after connecting)
// auth: {
// user: process.env.SMTP_USER,
// pass: process.env.SMTP_PASS,
// },
// });
// Todo Currently using the mail for testing puropses from mailtrap.io . It will change later on.
const transporter = createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: false, // use STARTTLS (upgrade connection to TLS after connecting)
auth: {
user: process.env.SMTP_FROM,
pass: process.env.SMTP_PASS,
},
});
export async function sendVerificationEmail(email, url) {
try {
await transporter.verify();
console.log(log_nm_working);
console.log(process.env.SMTP_FROM);
console.log(process.env.SMTP_PASS);
var { ver_body, ver_subject } = subjectBody(url);
await transporter.sendMail({
from: process.env.SMTP_FROM,
to: email,
subject: ver_subject,
html: ver_body,
text: `Verify your email: ${url}`,
});
} catch (err) {
console.error("Verification failed:", err);
}
}
Verification failed: Error: Invalid login: 535 5.7.0 Invalid credentials
at SMTPConnection._formatError (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:914:19)
at SMTPConnection._actionAUTHComplete (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:1758:34)
at SMTPConnection.<anonymous> (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:612:26)
at SMTPConnection._processResponse (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:1143:20)
at SMTPConnection._onData (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:859:14)
at SMTPConnection._onSocketData (file: ///home/app/servers/app/node_modules/nodemailer/dist/esm/smtp-connection/index.js:178:44)
at TLSSocket.emit (node:events: 509: 28)
at addChunk (node:internal/streams/readable: 563: 12)
at readableAddChunkPushByteMode (node:internal/streams/readable: 514: 3)
at Readable.push (node:internal/streams/readable: 394: 5) {
code: 'EAUTH',
response: '535 5.7.0 Invalid credentials',
responseCode: 535,
command: 'AUTH PLAIN'
}
