nodemailer && mailtrap -> 连接 ETIMEDOUT 错误
nodemailer && mailtrap -> connect ETIMEDOUT error
我正在 nextjs 中开发一个虚拟项目,并尝试使用 mailtrap 向用户电子邮件发送重置密码消息,并且nodemailer 但是我有一个问题,当我发送请求时,我找不到任何解决方案,这个错误发生了
Error: connect ETIMEDOUT 18.215.44.90:2525
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4039,
code: 'ESOCKET',
syscall: 'connect',
address: '18.215.44.90',
port: 2525,
command: 'CONN'
}
和这是我的代码
import nodemailer from "nodemailer";
async function SendEmail(options) {
const transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "b4f46aa8ab49eb",
pass: "100f5d80facf4d",
},
});
const message = {
from: `${process.env.SMTP_FROM_NAME} <${process.env.SMTP_FROM_EMAIL}>`,
to: options.email,
subject: options.subject,
text: options.message,
};
await transport.sendMail(message, (error, info) => {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
}
export default SendEmail;
换个端口试试,换一个internet网络试试,有时候服务商提供的ip被封了,我也出现同样的错误,我的解决办法是换internet网络。
我正在 nextjs 中开发一个虚拟项目,并尝试使用 mailtrap 向用户电子邮件发送重置密码消息,并且nodemailer 但是我有一个问题,当我发送请求时,我找不到任何解决方案,这个错误发生了
Error: connect ETIMEDOUT 18.215.44.90:2525
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4039,
code: 'ESOCKET',
syscall: 'connect',
address: '18.215.44.90',
port: 2525,
command: 'CONN'
}
和这是我的代码
import nodemailer from "nodemailer";
async function SendEmail(options) {
const transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "b4f46aa8ab49eb",
pass: "100f5d80facf4d",
},
});
const message = {
from: `${process.env.SMTP_FROM_NAME} <${process.env.SMTP_FROM_EMAIL}>`,
to: options.email,
subject: options.subject,
text: options.message,
};
await transport.sendMail(message, (error, info) => {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
}
export default SendEmail;
换个端口试试,换一个internet网络试试,有时候服务商提供的ip被封了,我也出现同样的错误,我的解决办法是换internet网络。