admin管理员组文章数量:1431420
I am using smtp.emailcloud.smartping.io as my SMTP service provider. The emails are sent on my localhost successfully. But not sending on my server getting below error :
SendMail error: ==>> Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -104,
code: 'ESOCKET',
syscall: 'read',
command: 'CONN'
}
my code is as below :
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
tls: {
rejectUnauthorized: false
},
dnsTimeout: 180000, //3 minutes timeout
debug: true,
logger: true,
})
const sendEmail = async (emailData) => {
try {
const { senderEmail, sendTo, subject, emailBody, attachmentName } = emailData;
const attachmentPath = path.join(process.cwd(), 'uploads/attachments', attachmentName);
const mailOptions = {
from: senderEmail,
to: sendTo,
subject: subject,
html: emailBody,
attachments: attachmentName !== 'null'
? [
{
filename: attachmentName,
path: attachmentPath
}
]
: []
}
if (emailData) {
mailOptions['cc'] = emailData;
}
console.log('mailOptions', mailOptions);
// transporter.sendMail(mailOptions)
transporter.sendMail(mailOptions)
.then(info => console.log('Email sent: ==>>', info))
.catch(error => console.error('SendMail error: ==>>', error));
} catch (error) {
console.log('error -->>', error);
Sentry.captureMessage("Something went wrong in sendEmail util function");
Sentry.captureException(error);
}
};
I have tried below changes in config :
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
tls: {
rejectUnauthorized: false
},
dnsTimeout: 180000, //3 minutes timeout
debug: true,
logger: true,
})
I have tried several solutions from google but did not work.
It would be greate if you help me to resolve it.
Thank you
I am using smtp.emailcloud.smartping.io as my SMTP service provider. The emails are sent on my localhost successfully. But not sending on my server getting below error :
SendMail error: ==>> Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -104,
code: 'ESOCKET',
syscall: 'read',
command: 'CONN'
}
my code is as below :
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
tls: {
rejectUnauthorized: false
},
dnsTimeout: 180000, //3 minutes timeout
debug: true,
logger: true,
})
const sendEmail = async (emailData) => {
try {
const { senderEmail, sendTo, subject, emailBody, attachmentName } = emailData;
const attachmentPath = path.join(process.cwd(), 'uploads/attachments', attachmentName);
const mailOptions = {
from: senderEmail,
to: sendTo,
subject: subject,
html: emailBody,
attachments: attachmentName !== 'null'
? [
{
filename: attachmentName,
path: attachmentPath
}
]
: []
}
if (emailData) {
mailOptions['cc'] = emailData;
}
console.log('mailOptions', mailOptions);
// transporter.sendMail(mailOptions)
transporter.sendMail(mailOptions)
.then(info => console.log('Email sent: ==>>', info))
.catch(error => console.error('SendMail error: ==>>', error));
} catch (error) {
console.log('error -->>', error);
Sentry.captureMessage("Something went wrong in sendEmail util function");
Sentry.captureException(error);
}
};
I have tried below changes in config :
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
tls: {
rejectUnauthorized: false
},
dnsTimeout: 180000, //3 minutes timeout
debug: true,
logger: true,
})
I have tried several solutions from google but did not work.
It would be greate if you help me to resolve it.
Thank you
Share Improve this question edited Nov 20, 2024 at 6:20 JIGNESH PATEL asked Nov 19, 2024 at 12:49 JIGNESH PATELJIGNESH PATEL 3975 silver badges20 bronze badges2 Answers
Reset to default 1Can you check the sever network configuration and firewall configuration please?
Before I had a similar problem with NodeJS server but after fixing firewall configuration using ufw
or firewalld
, it was fine.
After trying many solutions from Google and StackOverflow. I came to know that my code is correct the issue was with SMTP credentials. I have used other SMTP credentials and it worked.
本文标签: nodejsemails are not sending using nodemailerStack Overflow
版权声明:本文标题:node.js - emails are not sending using nodemailer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745561184a2663480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论