I am using Google cloud functions to send emails using Nodemailer. I am using the MailComposer module to send emails with formatting (line breaks and HTML etc).
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. I have tried following the documentation and adding the keepBcc option with no success. Does anyone know what I am missing?