我正在寻找一个工作的c#示例,以添加list-unsubscribe用亚马逊ses。
阅读了Amazon-SES现在支持添加标题,我正在寻找C#示例,但找不到一个。
我找不到像Java一样的不错的API。对于C#,我找到了两个替代方案。
最简单的选择可能是切换到SMTP接口和.NET的本机SMTP类(或第三方库(:使用SMTP发送带有C#
的电子邮件示例代码使用System.Net.Mail
的MailMessage
类:
// Create and build a new MailMessage object
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress(FROM,FROMNAME);
message.To.Add(new MailAddress(TO));
message.Subject = SUBJECT;
message.Body = BODY;
// Comment or delete the next line if you are not using a configuration set
message.Headers.Add("X-SES-CONFIGURATION-SET", CONFIGSET);
另一个(较不吸引人(的选项是使用SendRawEmailRequest
。使用此API,您必须在MemoryStream
中对消息以及其标题,附件和其他数据进行编码。
示例代码,来自AWS SDK .NET文档-SES- rawMessage:
var sesClient = new AmazonSimpleEmailServiceClient();
var stream = new MemoryStream(
Encoding.UTF8.GetBytes("From: johndoe@example.comn" +
"To: janedoe@example.comn" +
"Subject: You're invited to the meetingn" +
"Content-Type: text/plainnn" +
"Please join us Monday at 7:00 PM.")
);
var raw = new RawMessage
{
Data = stream
};
var to = new List<string>() { "janedoe@example.com" };
var from = "johndoe@example.com";
var request = new SendRawEmailRequest
{
Destinations = to,
RawMessage = raw,
Source = from
};
sesClient.SendRawEmail(request);