在ASP.NET MVC(C#)中通过Amazon SNS配置Amazon SES反馈通知
作者:互联网
美好的一天!
我刚开始使用Amazon SES.
我想在我的asp.net mvc(C#)网站上使用它.
我下载并安装适用于Visual Studio的AWS Toolkit,创建AWS简单控制台应用程序.
所以,我有使用AmazonSimpleEmailService客户端发送电子邮件的示例代码.
第1部分:
using (AmazonSimpleEmailService client = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(RegionEndpoint.USEast1))
{
var sendRequest = new SendEmailRequest
{
Source = senderAddress,
Destination = new Destination { ToAddresses = new List<string> { receiverAddress } },
Message = new Message
{
Subject = new Content("Sample Mail using SES"),
Body = new Body { Text = new Content("Sample message content.") }
}
};
Console.WriteLine("Sending email using AWS SES...");
SendEmailResponse response = client.SendEmail(sendRequest);
Console.WriteLine("The email was sent successfully.");
}
此外,我必须通过Amazon SNS配置Amazon SES反馈通知.
我用示例代码找到了很好的主题:
第3部分:
http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/Handling-Bounces-and-Complaints
因此,我需要制作第2部分,我将获得ReceiveMessageResponse响应并将其发送到第3部分.
我需要在C#中实现这个步骤:
设置以下AWS组件以处理退回通知:
1. Create an Amazon SQS queue named ses-bounces-queue.
2. Create an Amazon SNS topic named ses-bounces-topic.
3. Configure the Amazon SNS topic to publish to the SQS queue.
4. Configure Amazon SES to publish bounce notifications using ses-bounces-topic to ses-bounces-queue.
我试着写下来:
// 1. Create an Amazon SQS queue named ses-bounces-queue.
AmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient(RegionEndpoint.USWest2);
CreateQueueRequest sqsRequest = new CreateQueueRequest();
sqsRequest.QueueName = "ses-bounces-queue";
CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
String myQueueUrl;
myQueueUrl = createQueueResponse.CreateQueueResult.QueueUrl;
// 2. Create an Amazon SNS topic named ses-bounces-topic
AmazonSimpleNotificationService sns = new AmazonSimpleNotificationServiceClient(RegionEndpoint.USWest2);
string topicArn = sns.CreateTopic(new CreateTopicRequest
{
Name = "ses-bounces-topic"
}).CreateTopicResult.TopicArn;
// 3. Configure the Amazon SNS topic to publish to the SQS queue
sns.Subscribe(new SubscribeRequest
{
TopicArn = topicArn,
Protocol = "https",
Endpoint = "ses-bounces-queue"
});
// 4. Configure Amazon SES to publish bounce notifications using ses-bounces-topic to ses-bounces-queue
clientSES.SetIdentityNotificationTopic(XObject);
我走在正确的轨道上?
我如何实施4部分?如何接收XObject?
谢谢!
解决方法:
您走在正确的轨道上 – 对于缺失的第4部分,您需要实现从步骤1中创建的Amazon SQS消息队列接收消息.请参阅我对Example of .net application using Amazon SQS的答案,了解在哪里可以找到相应的示例 – 它归结为以下内容码:
// receive a message
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
receiveMessageRequest.QueueUrl = myQueueUrl;
ReceiveMessageResponse receiveMessageResponse = sqs.
ReceiveMessage(receiveMessageRequest);
if (receiveMessageResponse.IsSetReceiveMessageResult())
{
Console.WriteLine("Printing received message.\n");
ReceiveMessageResult receiveMessageResult = receiveMessageResponse.
ReceiveMessageResult;
foreach (Message message in receiveMessageResult.Message)
{
// process the message (see below)
}
}
在循环中,您需要调用ProcessQueuedBounce()或ProcessQueuedComplaint(),如Handling Bounces and Complaints所示.
标签:c,amazon-web-services,amazon-ses 来源: https://codeday.me/bug/20190624/1282861.html