[英]BBC emails not being sent with MailComposer and Nodemailer
I am using Google cloud functions to send emails using Nodemailer.我正在使用 Google 云功能使用 Nodemailer 发送电子邮件。 I am using the MailComposer module to send emails with formatting (line breaks and HTML etc).
我正在使用 MailComposer 模块发送带有格式的电子邮件(换行符和 HTML 等)。
Here is my code:这是我的代码:
const mailOptions = {
from: `${name} joanne@bloggs.com`,
replyTo: `${name} ${email}`,
to: user.email,
bcc: 'jo@bloggs.com',
subject: `Direct message from ${name}`,
text: `${message}`
}
let mail = new MailComposer(mailOptions).compile()
mail.keepBcc = true
console.log('mail', mail)
return mail.build((error, message) => {
if (error) {
console.log('Email unsuccessful', error)
res.status(400).send(error)
}
const dataToSend = {
to: user.email,
bcc: 'jo@bloggs.com',
message: message.toString('ascii')
}
return mailgun.messages().sendMime(dataToSend, sendError => {
if (sendError) {
console.log('Email unsuccessful', error)
res.status(400).send(error)
}
return res.send('Email successfully sent!')
})
})
The problem I am having is that emails are not sent to the BBC recipient, but are sent to the TO recipient.我遇到的问题是电子邮件没有发送给 BBC 收件人,而是发送给收件人。 I have tried following the documentation and adding the keepBcc option with no success.
我尝试按照文档添加 keepBcc 选项,但没有成功。 Does anyone know what I am missing?
有谁知道我错过了什么?
So this was two years ago but if anyone else has the same question, here's how I solved it.所以这是两年前的事了,但如果其他人有同样的问题,这就是我解决它的方法。
NodeMailer's MailComposer drops the BCC header when it's built. NodeMailer 的 MailComposer 在构建时会删除 BCC header。 So to avoid that from happening, after you compile you must turn on the keepBcc flag.
因此,为避免这种情况发生,编译后必须打开 keepBcc 标志。 Basically, you would do this:
基本上,你会这样做:
var mail = new MailComposer(mailOptions).compile(); mail.keepBcc = true; mail.build(function(err, message){ console.log(message); }
But be sure to compile before turning on the keepBcc flag or it won't work.但是一定要在打开keepBcc标志之前编译,否则它将不起作用。 You can read more about why this happens here .
您可以在此处阅读更多关于为什么会发生这种情况的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.