AWS SES SendRawEmailAsync不接受BCC

时间:2016-08-05 17:00:31

标签: amazon-web-services sdk amazon-ses bcc

我使用AWS SES Api发送电子邮件,将邮件消息转换为流,但我无法发送BCC。

private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  if (tabBDEAdjust.IsSelected)
  {
     MessageBox.Show("hello");
     e.Handled = true;
  }
}

BCC已经进入了mailMessage对象,因此当它转换为raw时,它也应该包含BCC到头文件中。我试过包含/排除目的地,它给出了相同的结果。

任何帮助都非常感激。

1 个答案:

答案 0 :(得分:1)

所以最后通过对代码进行了以下2次更改来使其工作

1 - 在SendMessageUsingAWSProfileAsync(删除desintation,因为它不接受BCC

                var sendRequest = new SendRawEmailRequest(rawMessage)
                {
                    Source = mailMessage.From.Address, // Destionation is removed from here intenationally as it stop doing BCC

}

2 - 在ConvertMailMessageToMemoryStream中,在从邮件消息创建流时包含BCC标头

// BCC is not included by default, so need to include it.
        if (message.Bcc.Count > 0)
        {
            MethodInfo writeHeadersMethod = mailWriter.GetType().GetMethod("WriteHeaders", BindingFlags.Instance | BindingFlags.NonPublic);
            System.Collections.Specialized.NameValueCollection bccHeaders = new System.Collections.Specialized.NameValueCollection();
            bccHeaders.Add("BCC", string.Join(",", message.Bcc.Select(b => b.Address)));
            writeHeadersMethod.Invoke(mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { bccHeaders, false }, null);
        }