jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
577 stars 129 forks source link

Amazon ses callback error #135

Closed gabrielpeixoto closed 3 years ago

gabrielpeixoto commented 3 years ago

I simulate a POST request using that example: (From: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-examples.html)

  {
      "notificationType":"Delivery",
      "mail":{
         "timestamp":"2016-01-27T14:59:38.237Z",
         "messageId":"0000014644fe5ef6-9a483358-9170-4cb4-a269-f5dcdf415321-000000",
         "source":"john@example.com",
         "sourceArn": "arn:aws:ses:us-west-2:888888888888:identity/example.com",
         "sourceIp": "127.0.3.0",
         "sendingAccountId":"123456789012",
         "destination":[
            "jane@example.com"
         ], 
          "headersTruncated":false,
          "headers":[ 
           { 
              "name":"From",
              "value":"\"John Doe\" <john@example.com>"
           },
           { 
              "name":"To",
              "value":"\"Jane Doe\" <jane@example.com>"
           },
           { 
              "name":"Message-ID",
              "value":"custom-message-ID"
           },
           { 
              "name":"Subject",
              "value":"Hello"
           },
           { 
              "name":"Content-Type",
              "value":"text/plain; charset=\"UTF-8\""
           },
           { 
              "name":"Content-Transfer-Encoding",
              "value":"base64"
           },
           { 
              "name":"Date",
              "value":"Wed, 27 Jan 2016 14:58:45 +0000"
           }
          ],
          "commonHeaders":{ 
            "from":[ 
               "John Doe <john@example.com>"
            ],
            "date":"Wed, 27 Jan 2016 14:58:45 +0000",
            "to":[ 
               "Jane Doe <jane@example.com>"
            ],
            "messageId":"custom-message-ID",
            "subject":"Hello"
          }
       },
      "delivery":{
         "timestamp":"2016-01-27T14:59:38.237Z",
         "recipients":["jane@example.com"],
         "processingTimeMillis":546,     
         "reportingMTA":"a8-70.smtp-out.amazonses.com",
         "smtpResponse":"250 ok:  Message 64111812 accepted",
         "remoteMtaIp":"127.0.2.0"
      } 
   }

this is returning the error:

InvalidArgumentException: &quot;Message&quot; is required to verify the SNS Message. in file C:\laragon\www\Escavador\vendor\aws\aws-php-sns-message-validator\src\Message.php on line 150
Stack trace:
  1. InvalidArgumentException-&gt;() C:\laragon\www\Escavador\vendor\aws\aws-php-sns-message-validator\src\Message.php:150
  2. Aws\Sns\Message-&gt;validateRequiredKeys() C:\laragon\www\Escavador\vendor\aws\aws-php-sns-message-validator\src\Message.php:85
  3. Aws\Sns\Message-&gt;__construct() C:\laragon\www\Escavador\vendor\aws\aws-php-sns-message-validator\src\Message.php:71
  4. Aws\Sns\Message-&gt;fromJsonString() C:\laragon\www\Escavador\vendor\aws\aws-php-sns-message-validator\src\Message.php:44
  5. Aws\Sns\Message-&gt;fromRawPostData() C:\laragon\www\Escavador\vendor\jdavidbakr\mail-tracker\src\SNSController.php:30
jdavidbakr commented 3 years ago

It's not quite that simple. The AWS SDK validates the incoming message so that it can't be forged. The only way to actually test it is to either mock the validation process (see the tests in the package) or send it a real notification.