私はノードjSを使用してメールを送信するためにSendgridを使用しています。ノードjsメールを送信メールアドレスから空にします(必要)
私は送信元アドレスを指定したにもかかわらず、私は「メールアドレスから空にする(必須)」を取得しています。
メールはユーザーの登録時に送信されますが、以下の関数呼び出しではエラーが発生します。私のルートで
/orders.js
// Start Sendgrid Configuration Settings
var options = {
auth: {
api_user: 'user123', // Sendgrid username
api_key: '$user123' // Sendgrid password
}
}
var client = nodemailer.createTransport(sgTransport(options));
// End Sendgrid Configuration Settings
router.post('/changeStatus', (req, res, next) => {
Orders.changeStatus(req.body.status, req.body.id, (err, orders) => {
if (err) {
res.json({ success: false, msg: 'No Orders' });
}
else {
Orders.getUserByOrderNo(req.body.id, (err, user) => {
//Send mail on success
var email = {
from: 'Localhost Staff, [email protected]',
to: user[0].user_id.email,
subject: 'Welcome to ABC',
text: 'Hello ' + user[0].user_id.username + ', thank you for registering at Food4Smiles.com. ',
html: 'Hello<strong> ' + user[0].user_id.username + '</strong>,<br><br>Thank you for registering at ABC.com. '
};
// Function to send e-mail to the user
client.sendMail(user[0].user_id.email, function (err, info) {
if (err) {
console.log(err); // If error with sending e-mail, log to console/terminal
}
else {
console.log('Mesage sent !!' + info.response);
}
});
})
res.json({ success: true, order: orders });
}
});
})
モデル/ orders.js
module.exports.getUserByOrderNo = function (orderNo, callback) {
console.log(orderNo)
Orders.find({ orderNo: orderNo }).populate('user_id').exec(callback)
}
全エラースタックトレース:
Error: Empty from email address (required)
at Request._callback (/var/www/html/Express/Local-MEAN-dev/node_modules/sendgrid/lib/sendgrid.js:88:25) at Request.self.callback (/var/www/html/Express/Local-MEAN-dev/node_modules/request/request.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:194:7) at Request. (/var/www/html/Express/Local-MEAN-dev/node_modules/request/request.js:1171:10) at emitOne (events.js:96:13) at Request.emit (events.js:191:7) at IncomingMessage. (/var/www/html/Express/Local-MEAN-dev/node_modules/request/request.js:1091:12) at Object.onceWrapper (events.js:293:19) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:188:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)