我有一个C#应用程序,它使用Amazon SES发送电子邮件。我想要做的是当我获得退回或回复电子邮件时,使用lambda函数在我的应用程序中调用端点。我有以下C#Lambda函数,它有效,但有两个问题。 我无法弄清楚如何识别故障。 2.我找不到用户的消息文本。
public async Task FunctionHandler(Amazon.Lambda.SimpleEmailEvents.SimpleEmailEvent emailEvent, ILambdaContext context)
{
foreach (Amazon.Lambda.SimpleEmailEvents.SimpleEmailEvent.SimpleEmailRecord record in emailEvent.Records)
{
Amazon.Lambda.SimpleEmailEvents.SimpleEmailEvent.SimpleEmailService sesRecord = record.Ses;
LambdaLogger.Log($"Processing message {sesRecord.Mail.MessageId}.");
using (HttpClient client = new HttpClient())
{
try
{
string messageId = sesRecord.Mail.MessageId;
string to = string.Empty;
if (sesRecord.Mail.Destination != null && sesRecord.Mail.Destination.Count > 0)
{
to = sesRecord.Mail.Destination.First();
}
StringContent requestContent = new StringContent(JsonConvert.SerializeObject(new { MessageId = messageId, To = to }), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("http://xxxx", requestContent);
response.EnsureSuccessStatusCode();
string stringResponse = await response.Content.ReadAsStringAsync();
}
catch (HttpRequestException e)
{
Console.WriteLine($"Request exception: {e.Message}");
}
}
}
}
这不是正确的做法吗?我还阅读了使用SES和SNS来实现这一目标,但我想尽可能避免添加另一层。
答案 0 :(得分:0)
这应该设置为AWS在此处概述的自动化流程,并包含示例代码(C#)。 http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/-Handling-span-class-matches-Bounces-span-and-Complaints.pdf