最近一直在使用node-imap并尝试实现发送电子邮件。这是feathers / node上的代码:
create(data, params) {
return new Promise((resolve, reject) => {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: this.host,
port: this.smtpPort,
secure: false, // true for 465, false for other ports,
tls: {
rejectUnauthorized: false
},
auth: {
user: this.emailUsername, // generated ethereal user
pass: this.emailPassword // generated ethereal password
}
});
// setup email data with unicode symbols
let mailOptions = {
from: this.emailUsername, // sender address
to: data.to, // list of receivers
subject: data.subject, // Subject line
text: data.body, // plain text body
html: data.body // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
reject(error);
//console.log(error);
}
//console.log('Message sent: %s', info.messageId);
return resolve(info);
});
});
}
这段代码可以正常运行并按需发送电子邮件,但是在完成其工作后,我无法在“已发送”框中找到这些电子邮件...经验丰富的node-imap的人,我想念什么?干杯。
编辑::刚刚意识到它确实为某些电子邮件提供商(Gmail,Hotmail)保存了它,但对于另一些电子邮件提供商却没有。因此,我想我不会丢失任何东西……但是我如何手动将其保存给其他没有自动执行的提供者。
看来问题出在电子邮件提供商上,原因是此代码对Gmail或Hotmail来说效果很好...所以我所做的是在已为特定电子邮件提供商发送了电子邮件之后,将电子邮件手动附加到“已发送”框中...这是代码(如果有)1需要:
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
reject(error);
//console.log(error);
}
if (checkEmail(userEmail) == 'linksoft') {
imap.once('ready', function () {
imap.openBox('inbox.Sent', false, (err, box) => {
if (err) throw err;
let msg, htmlEntity, plainEntity;
msg = mimemessage.factory({
contentType: 'multipart/alternate',
body: []
});
htmlEntity = mimemessage.factory({
contentType: 'text/html;charset=utf-8',
body: mailOptions.html
});
plainEntity = mimemessage.factory({
body: mailOptions.text
});
msg.header('Message-ID', '<1234qwerty>');
msg.header('From', mailOptions.from);
msg.header('To', mailOptions.to);
msg.header('Subject', mailOptions.subject);
msg.header('Date', new Date()));
//msg.body.push(htmlEntity);
msg.body.push(plainEntity);
imap.append(msg.toString());
})
});
imap.once('error', function (err) {
reject(err);
});
imap.once('end', function () {
resolve(response);
});
imap.connect();
}
//console.log('Message sent: %s', info.messageId);
return resolve(info);
});
相关性:mimemessage模块,用于在将其存储到“已发送”框中之前生成mime消息,因为imap.append()需要mime消息类型
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句