使用 C# Lambda 处理 SES 退回邮件和投诉



我有一个 C# 应用程序,它使用 Amazon SES 发送电子邮件。我想做的是在收到退回邮件或回复电子邮件时,使用 lambda 函数调用应用程序中的终端节点。我有以下 C# Lambda 函数,它可以工作,但有两个问题。1. 我不知道如何识别故障。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 来实现此目的的信息,但如果可能的话,我想避免添加另一层。

这实际上应该设置为一个自动化过程,AWS 在此处概述了该过程,并包含示例代码 (C#(。http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/-Handling-span-class-matches-Bounces-span-and-Complaints.pdf

最新更新