こんにちは、私はamazon sesを使用して添付ファイル付きbulkmailを送信しようとしています。添付ファイル付きのメールを送信することはできますが、送信したすべてのユーザーに対して自分の送信済みメールが表示されます。 bccフィールドに宛先メールを追加しようとしていますが、エラーEmpty required header 'To'
が送信されています。 これは、私はすでに試したものです:aws ses APIを使用して生のバルクメールを送信します.AIインターフェイス(空の必須のヘッダー 'To')
private static BodyBuilder GetMessageBody()
{
var body = new BodyBuilder()
{
HtmlBody = @"<p>Amazon SES Test body</p>",
TextBody = "Amazon SES Test body",
};
body.Attachments.Add(@"G:\me.jpg");
return body;
}
private static MimeMessage GetMessage()
{
var message = new MimeMessage();
List<string> to = new List<string>(50);
to.Add("[email protected]");
to.Add("[email protected]");
message.From.Add(new MailboxAddress(ConfigurationManager.AppSettings["senderaddress"], ConfigurationManager.AppSettings["senderaddress"]));
for (int i = 0; i < to.Count; i++)
{
message.Bcc.Add(new MailboxAddress(string.Empty,to[i]));
//message.To.Add(new MailboxAddress(string.Empty, "[email protected]"));
//message.To.Add(new MailboxAddress(string.Empty, "[email protected]"));
}
message.Subject = "Amazon SES Test";
message.Body = GetMessageBody().ToMessageBody();
return message;
}
private static MemoryStream GetMessageStream()
{
var stream = new MemoryStream();
GetMessage().WriteTo(stream);
return stream;
}
private void SendEmails()
{
var credentals = new BasicAWSCredentials(ConfigurationManager.AppSettings["AccessKey"], ConfigurationManager.AppSettings["SecretAccessKey"]);
using (var client = new AmazonSimpleEmailServiceClient(credentals, RegionEndpoint.USEast1))
{
var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(GetMessageStream()) };
try
{
var response = client.SendRawEmail(sendRequest);
}
catch (Exception e)
{
}
}
}