admin管理员组文章数量:1296331
Error: Connection timeout at SMTPConnection._formatError, don't know what is wrong, can't send mails,please help me. am trying to send a mail using nodemailer, but i keep getting this error in my console
Error: Connection timeout
at SMTPConnection._formatError (/home/codabae/Desktop/mailmonster/Backend/v1/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
code: 'ETIMEDOUT',
mand: 'CONN'
}
this is my api here i don't know what am doing wrong, i getting the details from the mongodb and am filling it in the nodmailer fields, i really don't know what am doing wrong.
router.post('/', auth, (req, res) => {
const { to, cc, bcc, subject, message, attachment, smtpDetails } = req.body;
if (!to || !subject || !message || !smtpDetails) return res.status(400).send('input cannot be empty')
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '...'
}
});
let mailOptions = {
from: '[email protected]',
to: to,
cc: cc,
bcc: bcc,
subject: subject,
text: `${message}`
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
res.send('mail not sent')
} else {
console.log('Email sent: ' + info.response);
res.send('mail sent')
}
});
module.exports = router;
Error: Connection timeout at SMTPConnection._formatError, don't know what is wrong, can't send mails,please help me. am trying to send a mail using nodemailer, but i keep getting this error in my console
Error: Connection timeout
at SMTPConnection._formatError (/home/codabae/Desktop/mailmonster/Backend/v1/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
code: 'ETIMEDOUT',
mand: 'CONN'
}
this is my api here i don't know what am doing wrong, i getting the details from the mongodb and am filling it in the nodmailer fields, i really don't know what am doing wrong.
router.post('/', auth, (req, res) => {
const { to, cc, bcc, subject, message, attachment, smtpDetails } = req.body;
if (!to || !subject || !message || !smtpDetails) return res.status(400).send('input cannot be empty')
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '...'
}
});
let mailOptions = {
from: '[email protected]',
to: to,
cc: cc,
bcc: bcc,
subject: subject,
text: `${message}`
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
res.send('mail not sent')
} else {
console.log('Email sent: ' + info.response);
res.send('mail sent')
}
});
module.exports = router;
Share
Improve this question
edited Feb 2, 2020 at 23:06
Onyinyechi Precious Onyenauche
asked Feb 1, 2020 at 20:22
Onyinyechi Precious OnyenaucheOnyinyechi Precious Onyenauche
2953 gold badges6 silver badges19 bronze badges
2
- Did you find a solution for this - I am stuck at the same issue – vivianaranha Commented Apr 4, 2020 at 20:54
- check if your wifi provider has allowed access to the smtp servers. in my case my college wifi blocked the request, i tried my phone hotspot it worked fine. – Aviroxi Commented Dec 21, 2022 at 10:41
1 Answer
Reset to default 7The part of the error message to focus on here is SMTPConnection._formatError
. You are receiving this error because the transport configuration variables are not correct. You need the following variables, with correct values for each.
There are additional variables that can be used, but based on the fields in your code, the following configuration should work fine. If you need additional info, you can always reference the Nodemailer documentation.
//transport configuration for user a site server to send an email.
let transporter = nodemailer.createTransport({
// This is the SMTP mail server to use for notifications.
// GCDS uses this mail server as a relay host.
host: "smtp.gmail.",
// SMTP is unlike most network protocols, which only have a single port number.
// SMTP has at least 3. They are port numbers 25, 587, and 465.
// Port 25 is still widely used as a **relay** port from one server to another.
// Port for SSL: 465
// Port for TLS/STARTTLS: 587
port: 465,
// if true the connection will use TLS when connecting to server. If false (the
// default) then TLS is used if server supports the STARTTLS extension. In most
// cases set this value to true if you are connecting to port 465. For port 587 or
// 25 keep it false
secure: true, // use TLS
auth: {
// Your full email address
user: process.env.SMTP_TO_EMAIL,
// Your Gmail password or App Password
pass: process.env.SMTP_TO_PASSWORD
}
});
You mentioned filling these in using some sort of information from MongoDB. I cannot see from where you are getting the variables and values in your configuration, but you may need to use a different source or update your query if you are pulling the values from a database.
NOTE: Another mon issue to be aware of involves using the Gmail password, which cannot be used if your account has 2FA enabled. In this case you must generate a unique App Password by following these guidelines from Google.
本文标签: javascriptError Connection timeout at SMTPConnectionformatErrorStack Overflow
版权声明:本文标题:javascript - Error: Connection timeout at SMTPConnection._formatError - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741631564a2389396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论