简体   繁体   English

电子邮件未在Amazon SES SendRawEmail(Node.JS)中显示To:,Cc和Bcc

[英]Email not showing To:, Cc, and Bcc in Amazon SES SendRawEmail (Node.JS)

Following up this solution about Adding CC and BCC when sending a RawEmail, I'm getting blank the To, Cc, and Bcc fields when receiving the email. 在发送RawEmail时,关于添加CC和BCC的解决方案 ,我收到电子邮件时收到To,Cc和Bcc字段的空白。 For quickest implementation, I'm using this OSS aws-thin-ses-node library. 为了最快的实现,我正在使用这个OSS aws-thin-ses-node库。

My send raw email method is defined as (to, cc and bcc are arrays, so I just have a little tweak with the asOptionalArray and asValueFromArray methods to send in the required format as defined in AWS SDK ). 我发送的原始电子邮件方法定义为(to,cc和bcc是数组,因此我只需要使用asOptionalArray和asValueFromArray方法进行一些调整,以便按AWS SDK中定义的格式发送)。

What could I improve to fix this minor issue that is nice to have it, although it is sending to all To, Cc and Bcc addresses? 虽然它发送到所有To,Cc和Bcc地址,但我可以通过哪些方法来改进这个很小的问题? I'm attaching my sendRawEmail and getRawMessages methods definitions as follow 我正在附加我的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
}

Send Raw email looks like: 发送原始电子邮件如下:

email_raw_without_to_cc_bcc

I finally figured out the solution and the problem was that I wasn't defining the To, Cc and Bcc in the ses mail headers, as suggested, my destinations array is empty now and rewrite my 我终于找到了解决方案,问题是我没有在ses邮件头中定义To,Cc和Bcc,如建议的那样,我的目标数组现在是空的并重写我的

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM