4

良い一日!Amazon SES を使い始めたばかりです。これを asp.net mvc (C#) Web サイトで使用したい。

AWS Toolkit for Visual Studio をダウンロードしてインストールし、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

したがって、ReceiveMessageResponse 応答を取得して PART 3 に送信する PART 2 を作成する必要があります。

この手順を 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

3 に答える 3

3

あなたは正しい道を進んでいます-欠落しているパート 4 については、ステップ 1 で作成した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()

于 2013-08-21T00:24:28.740 に答える
1

私は最近この問題に取り組む必要があり、.Net Web サイトからの SNS バウンス通知 (およびトピック サブスクリプション リクエスト) を処理する方法に関する適切なコード例を見つけることができませんでした。Amazon SES からの SNS バウンス通知を処理するために思いついた Web API メソッドを次に示します。

コードは VB ですが、オンラインのVB から C# へのコンバーターを使用すると、簡単に変換できます。

Imports System.Web.Http
Imports Amazon.SimpleNotificationService

Namespace Controllers
    Public Class AmazonController
        Inherits ApiController

        <HttpPost>
        <Route("amazon/bounce-handler")>
        Public Function HandleBounce() As IHttpActionResult

            Try
                Dim msg = Util.Message.ParseMessage(Request.Content.ReadAsStringAsync().Result)

                If Not msg.IsMessageSignatureValid Then
                    Return BadRequest("Invalid Signature!")
                End If

                If msg.IsSubscriptionType Then
                    msg.SubscribeToTopic()
                    Return Ok("Subscribed!")
                End If

                If msg.IsNotificationType Then

                    Dim bmsg = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Message)(msg.MessageText)

                    If bmsg.notificationType = "Bounce" Then

                        Dim emails = (From e In bmsg.bounce.bouncedRecipients
                                      Select e.emailAddress).Distinct()

                        If bmsg.bounce.bounceType = "Permanent" Then
                            For Each e In emails
                                'this email address is permanantly bounced. don't ever send any mails to this address. remove from list.
                            Next
                        Else
                            For Each e In emails
                                'this email address is temporarily bounced. don't send any more emails to this for a while. mark in db as temp bounce.
                            Next
                        End If

                    End If

                End If

            Catch ex As Exception
                'log or notify of this error to admin for further investigation
            End Try

            Return Ok("done...")

        End Function

        Private Class BouncedRecipient
            Public Property emailAddress As String
            Public Property status As String
            Public Property diagnosticCode As String
            Public Property action As String
        End Class

        Private Class Bounce
            Public Property bounceSubType As String
            Public Property bounceType As String
            Public Property reportingMTA As String
            Public Property bouncedRecipients As BouncedRecipient()
            Public Property timestamp As DateTime
            Public Property feedbackId As String
        End Class

        Private Class Mail
            Public Property timestamp As DateTime
            Public Property source As String
            Public Property sendingAccountId As String
            Public Property messageId As String
            Public Property destination As String()
            Public Property sourceArn As String
        End Class

        Private Class Message
            Public Property notificationType As String
            Public Property bounce As Bounce
            Public Property mail As Mail
        End Class

    End Class

End Namespace
于 2016-03-15T03:29:44.947 に答える