我正在寻找一个工作的C#示例,以添加列表-取消订阅标题与亚马逊SES。
在读到Amazon-SES现在支持添加头之后,我搜索了一个C#示例,但是找不到。
发布于 2018-02-26 15:12:43
我找不到nice API like they have for Java。对于C#,我找到了两个替代方案。
最简单的选择可能是切换到SMTP接口和.Net的原生SMTP类(或第三方库):Send an Email Using SMTP with C#
示例代码使用来自System.Net.Mail的MailMessage class
// 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 documentation - SES - RawMessage
var sesClient = new AmazonSimpleEmailServiceClient();
var stream = new MemoryStream(
Encoding.UTF8.GetBytes("From: johndoe@example.com\n" +
"To: janedoe@example.com\n" +
"Subject: You're invited to the meeting\n" +
"Content-Type: text/plain\n\n" +
"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);https://stackoverflow.com/questions/48981977
复制相似问题