如何通过nodejs中的nodemailer npm不使用电子邮件凭证发送邮件?
我知道如何使用nodemailer发送邮件,但我使用的是电子邮件凭据,但我不想使用它。有没有其他发送邮件的方法。
我的nodemailer代码片段是
var nodemailer = require('nodemailer');
// Not the movie transporter!
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]', // Your email id
pass: 'password' // Your password
}
});
module.exports =
{
sendEmail: function sendMail(varhtml,vartext, varsubject,varfrom, varfrom_name,varto, varto_name, reply_to_email ) {
//setup e-mail data with unicode symbols
var mailOptions = {
from: varfrom_name, // sender address
// to: ['[email protected]','[email protected]'], // list of receivers
// to: ['[email protected],[email protected]'], // list of receivers
// to: '[email protected]','[email protected]', // list of receivers
to: varto, // list of receivers
subject: varsubject, // Subject line
text: vartext, // plaintext body
html: varhtml // html body
};
console.log(mailOptions);
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
}else{
return console.log(info);
}
});
}
}
在上面的代码中,我也不会更改我的发件人姓名。如果我想从其他邮件发送像
vi可ask oh里[email protected]
但它会自动从我在这里使用凭据的邮件发送
vi可ask oh里@email
我也尝试使用sendmail npm,他们不需要任何凭据,但它在垃圾邮件文件夹中发送邮件
我的sendmail代码段
var sendmail = require('sendmail')({silent: true})
sendmail({
from: '[email protected]',
to: '[email protected],[email protected]',
subject: varsubject, // Subject line
html: varhtml,
attachments: [
]
}, function (err, reply) {
console.log(err && err.stack)
console.dir(reply)
});
回答如下:
我像你的底部代码一样使用sendmail,它对我来说很好。它可能是垃圾邮件的原因可能是因为您在电子邮件提供商中的设置。很可能您选择作为发件人的电子邮件(@ email)似乎是该服务提供商或您的设置的垃圾邮件。