Nodemailer - 电子邮件发送但没有收到
问题描述:
我使用feathersjs构建了一个API,并且需要发送附件的电子邮件。Nodemailer - 电子邮件发送但没有收到
该电子邮件似乎是发送,但我什么都没收到。
在我mail.service.js
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: '[email protected]',
pass: 'MyPassWord'
}
});
// Check the connection to the service.
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take our messages');
}
});
然后在我的钩
hook => {
const file = hook.params.file;
const email = {
from: '[email protected]', // sender address
to: '[email protected]', // list of receivers
subject: 'Test Nodemailer', // Subject line
// text: req.body.text, // plaintext body
html: '<b>Hello world </b>', // html body
attachments: [
{
filename: file.originalname,
contents: new Buffer(file.buffer, 'base64'),
encoding: 'base64'
}
]
};
return hook.app.service('mail').create(email)
.then(function (result) {
console.log('Sent email', result);
}).catch(err => {
console.log(err);
});
}
后来我
服务器准备采取我们的信息
发电子邮件
对象{来自: “[email protected]”,到: “[email protected]”,主题: “测试Nodemailer”,HTML: “世界,你好”}
我不知道如何检查问题的来源。
答
好吧,我知道了!
我需要添加transporter.sendMail()
的mail.class.js
里面,当我打电话hook.app.service('mail').create(email)
工作和attachement文件为0字节的邮件,但我的变量中良好的尺寸来触发这个动作。