2013-08-13 3 views
4

안녕하세요! 방금 ​​Amazon SES를 시작했습니다. 내 asp.net mvc (C#) 웹 사이트에서 이것을 사용하고 싶습니다.ASP.NET MVC (C#)의 Amazon SNS를 통한 Amazon SES 피드백 알림 구성

Visual Studio 용 AWS Toolkit을 다운로드하여 설치하고 AWS 간단한 콘솔 응용 프로그램을 만듭니다. 그래서 AmazonSimpleEmailService 클라이언트를 사용하여 전자 메일을 보낼 수있는 샘플 코드가 있습니다.

PART 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."); 
} 

, 나는 아마존 SNS를 통해 아마존 SES 피드백 알림을 구성해야합니다.

3 부 : 나는 샘플 코드 좋은 주제를 찾을 수 http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/Handling-Bounces-and-Complaints

그래서, 내가 할 필요를 내가 ReceiveMessageResponse 반응을 얻고 내가 구현할 필요 3.

PART로 보내드립니다 PART 2 C#에서이 단계 :

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. 

내가 그것을 쓰기 시도 :

012,351 알림을 반송 처리하기 위해 다음과 같은 AWS 구성 요소를 설정
// 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 수신 방법

감사합니다.

답변

3

오른쪽 트랙에 있습니다. 누락 된 파트 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) 
    } 
} 

당신은 Handling Bounces and Complaints에 도시 된 바와 같이 ProcessQueuedBounce() 또는 ProcessQueuedComplaint() 중 하나를 호출해야합니다.

+0

고맙습니다! 하지만 SQS없이 SNS 알림 수신을 구현합니다. 이것이 SQS 없이도 효과가 있기를 바랍니다. –

+1

안녕하세요, [처리 반송 및 불만] (http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/Handling-Bounces-and-Complaints) SES 블로그 게시물을 작성했습니다. SQS 대신 HTTP/S 엔드 포인트를 사용하는 경우 반송 및 불만 처리가 정상적으로 작동합니다. 그러나 SNS는 인터넷 문제로 인해 HTTP/S 종단점 (http://aws.amazon.com/sns/faqs/#49)으로의 배송을 보장 할 수 없습니다. 샘플 코드에서 SQS를 사용한 이유는 SQS 전달에 대한 SNS가 훨씬 더 높은 안정성을 가지고 있었기 때문이며 바운스 및 불만 처리는 대개 중요한 작업으로 간주됩니다. –

1

최근이 문제를 해결해야했으며 .Net 웹 사이트에서 SNS 반송 알림 (주제 가입 요청은 물론)을 처리하는 방법에 대한 좋은 코드 예제를 찾을 수 없었습니다. Amazon SES에서 SNS 바운스 알림을 처리하기 위해 생각해 낸 웹 API 방법은 다음과 같습니다.

코드는 VB이지만 온라인 VB to C# converter은 쉽게 변환 할 수 있어야합니다.

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