为什么我的 angular/express nodemailer 不包含电子邮件的发件人部分?
Why does my angular/express nodemailer not include the from portion of email?
我正在使用 Angular/Express 测试 nodemailer,它发送的电子邮件具有相同的 from/to 电子邮件,我自己的。我在 req.body.email 中收集了发件人的电子邮件地址,但并未按原样发送。我的快递代码:
var ContactUs = require('./contactUs.model');
var nodemailer = require("nodemailer");
// Creates a new contactUs in the DB.
exports.create = function(req, res) {
console.log("export controller hit")
console.log(req.body.email);
var message = {
// sender info
from: '"Contact Us from" <req.body.email>',
// Comma separated list of recipients
to: '"Receiver Name" <myemail>',
// Subject of the message
subject: req.body.email, // this is supposed to be req.body.name,
// but I changed it because it's not sending the from email.
text: req.body.comments
};
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'myemail',
pass: 'mypass'
}
});
transporter.sendMail(message, function(error, info) {
if (error) {
console.log('Error occurred');
console.log(error.message);
res.end("error");
return;
}
console.log('Message sent successfully!');
console.log('Server responded with "%s"', info.res);
res.end("sent");
})
}
像给定的格式一样使用req.body.email,它应该
from: "Contact Us from <"+req.body.email+">"
我正在使用 Angular/Express 测试 nodemailer,它发送的电子邮件具有相同的 from/to 电子邮件,我自己的。我在 req.body.email 中收集了发件人的电子邮件地址,但并未按原样发送。我的快递代码:
var ContactUs = require('./contactUs.model');
var nodemailer = require("nodemailer");
// Creates a new contactUs in the DB.
exports.create = function(req, res) {
console.log("export controller hit")
console.log(req.body.email);
var message = {
// sender info
from: '"Contact Us from" <req.body.email>',
// Comma separated list of recipients
to: '"Receiver Name" <myemail>',
// Subject of the message
subject: req.body.email, // this is supposed to be req.body.name,
// but I changed it because it's not sending the from email.
text: req.body.comments
};
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'myemail',
pass: 'mypass'
}
});
transporter.sendMail(message, function(error, info) {
if (error) {
console.log('Error occurred');
console.log(error.message);
res.end("error");
return;
}
console.log('Message sent successfully!');
console.log('Server responded with "%s"', info.res);
res.end("sent");
})
}
像给定的格式一样使用req.body.email,它应该
from: "Contact Us from <"+req.body.email+">"