关于在发送rawemail时添加cc和bcc的后续this solution,我在接收电子邮件时将“收件人”、“抄送”和“密件抄送”字段留空。为了最快的实现,我使用这个ossaws-thin-ses-node库。
我的send raw email方法被定义为(to、cc和bcc是数组,所以我只是对asoptionalarray和asvaluefromrarray方法进行了一些调整,以便以AWS SDK中定义的所需格式发送)。
我可以改进什么来解决这个小问题,很高兴有它,虽然它是发送到所有收件人,抄送和密件抄送地址?我将我的sendrawemail和getrawmessages方法定义附加如下
sendRawEmail: async ({ to, cc, bcc data}) => {
let destinations
if (cc && cc.length && bcc && bcc.length) {
destinations = [...cc, ...bcc]
destinations.unshift(asValueFromArray(to, 0))
} else {
destinations = to
}
const params = {
Destinations: asOptionalArray(destinations),
To: to instanceof Array ? to : asOptionalArray(to),
Cc: asOptionalArray(cc),
Bcc: asOptionalArray(bcc),
RawMessage: {
Data: await getRawMessage(data)
}
}
return client.sendEmail(params)
}
const getRawMessage = (data) => {
const template = getReportTemplate()
const subject = getSubject()
const reportName = getReportName()
let sesMail = 'From: noReply <' + noreplyEmail + '>\n'
sesMail += 'Subject: ' + subject + '\n'
sesMail += 'MIME-Version: 1.0\n'
sesMail += 'Content-Type: multipart/mixed; boundary="NextPart"\n\n'
sesMail += '--NextPart\n'
sesMail += 'Content-Type: text/html\n\n'
sesMail += template.report + '\n\n'
sesMail += '--NextPart\n'
sesMail += 'Content-Type: application/msexcel; name="' + reportName + '"\n'
sesMail += 'Content-Transfer-Encoding: base64\n'
sesMail += 'Content-Disposition: attachment\n\n'
sesMail += data.toString('base64') + '\n\n'
sesMail += '--NextPart--'
// eslint-disable-next-line
const base64Encoded = new Buffer.from(sesMail).toString('base64')
return base64Encoded
}
发送原始电子邮件看起来像:
最佳答案
我终于找到了解决方案,问题是我没有在ses邮件头中定义to、cc和bcc,正如建议的那样,我的destinations数组现在是空的,请重写我的
const getRawMessage = (to, cc, bcc, data) => {
const template = getReportTemplate()
const subject = getSubject()
const reportName = getReportName()
let sesMail = 'From: noReply <' + noreplyEmail + '>\n'
sesMail += 'To: ' + asValueFromArray(to, 0) + '\n'
sesMail += cc && cc.length ? 'Cc: ' + asOptionalArray(cc) + '\n' : ''
sesMail += bcc && bcc.length ? 'Bcc: ' + asOptionalArray(bcc) + '\n' : ''
sesMail += 'Subject: ' + subject + '\n'
sesMail += 'MIME-Version: 1.0\n'
sesMail += 'Content-Type: multipart/mixed; boundary="NextPart"\n\n'
sesMail += '--NextPart\n'
sesMail += 'Content-Type: text/html\n\n'
sesMail += template.report + '\n\n'
sesMail += '--NextPart\n'
sesMail += 'Content-Type: application/msexcel; name="' + reportName + '"\n'
sesMail += 'Content-Transfer-Encoding: base64\n'
sesMail += 'Content-Disposition: attachment\n\n'
sesMail += data.toString('base64') + '\n\n'
sesMail += '--NextPart--'
// eslint-disable-next-line
const base64Encoded = new Buffer.from(sesMail).toString('base64')
return base64Encoded
}