![](/img/trans.png)
[英]Node.js and Nodemailer: Can we attached PDF documents to emails?
[英]Sending concurrent emails with Nodemailer in Node.js
當有人在我的網站上填寫表格時,我正在嘗試發送驗證電子郵件,並且我正在使用 nodemailer 來實現這一點。
我的 node.js 代碼如下所示:
const express = require('express');
const app=express();
app.use(express.json());
app.post('/',(req,res)=>{
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
tls: {
ciphers:'SSLv3',
rejectUnauthorized: false
},
auth: {
user: 'generic-email@outlook.com',
pass: 'generic-password'
}
});
var mailOptions = {
from: 'generic-email@outlook.com',
to: req.body.email_name,
subject: 'testing <No-Reply Email>',
text: 'testing',
html: `<div>testing</div>`
};
transporter.sendMail(mailOptions, await function(error, info){
if(error)
{
console.log(error);
return res.json({stat:'not good'});
}
console.log('Message sent: ' + info.response);
return res.json({stat:'all good'});
});
});
app.listen(3000,()=>{
console.log('Listening at Port 3000...');
});
雖然它工作正常,但我懷疑如果多個人發出相同的請求,那么它會給出response: '421 concurrent connection limit in Avast exceeded(pass:0, processes:node.exe[46])
'錯誤。
當我嘗試遍歷代碼並向自己發送 300 封電子郵件以測試每天 email 限制的限制時出現此錯誤
網站上線時如何避免此錯誤?
到目前為止,我提出了兩種可能的解釋:
我可以循環代碼,以便不斷嘗試發送 email 直到它有機會
我將不得不使用 outlook 以外的其他服務
在這種情況下我能做什么? 我是否采取了正確的方法? 我應該使用其他一些 Email API 服務嗎? 我對所有這些 SMTP 東西都很陌生。
我認為問題是您正在為每個請求創建一個新連接,只需執行
const express = require('express');
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
tls: {
ciphers:'SSLv3',
rejectUnauthorized: false
},
auth: {
user: 'generic-email@outlook.com',
pass: 'generic-password'
}
});
const app=express();
app.use(express.json());
app.post('/',(req,res)=>{
var mailOptions = {
from: 'generic-email@outlook.com',
to: req.body.email_name,
subject: 'testing <No-Reply Email>',
text: 'testing',
html: `<div>testing</div>`
};
transporter.sendMail(mailOptions, await function(error, info){
if(error) {
console.log(error);
return res.json({stat:'not good'});
}
console.log('Message sent: ' + info.response);
return res.json({stat:'all good'});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.