Laravel How to get the MailJet response after an email message has been sent
Asked Answered
P

0

1

Based on this answer I want to track the status of an email, in order to determine if the system should try to resend the undelivered mail one more time.

I have created the listener:

class MailJetSentResponse
{
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(MessageSent $event)
    {
        //https://mcmap.net/q/1943454/-how-to-get-laravel-mail-response-after-send-function-called
        dd($event);
    }
}

And what I get from the dd() (by executing Laravel Tinker)

>>> Mail::mailer('smtp')->raw('Tinker mailjet test email message',function($msg) {$msg->to('[email protected]')->subject('What is the API response?');});

is:

      -messageId: "[email protected]"
      -debug: """
        < 220 in.mailjet.com ESMTP Mailjet\r\n
        > EHLO [127.0.0.1]\n
        < 250-smtpin.mailjet.com\r\n
        < 250-PIPELINING\r\n
        < 250-SIZE 15728640\r\n
        < 250-VRFY\r\n
        < 250-ETRN\r\n
        < 250-STARTTLS\r\n
        < 250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5\r\n
        < 250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5\r\n
        < 250-ENHANCEDSTATUSCODES\r\n
        < 250-8BITMIME\r\n
        < 250 SMTPUTF8\r\n
        > STARTTLS\n
        < 220 2.0.0 Ready to start TLS\r\n
        > EHLO [127.0.0.1]\n
        < 250-smtpin.mailjet.com\r\n
        < 250-PIPELINING\r\n
        < 250-SIZE 15728640\r\n
        < 250-VRFY\r\n
        < 250-ETRN\r\n
        < 250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5\r\n
        < 250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5\r\n
        < 250-ENHANCEDSTATUSCODES\r\n
        < 250-8BITMIME\r\n
        < 250 SMTPUTF8\r\n
        > AUTH CRAM-MD5\n
        < 334 PDExNTcxM_more_hash..._jg2MjcxMkBAtdnpybj4=\r\n
        > ZGJhNDc5YjAwMGRkOTQwZGFmYjdjNTI5YzJhYzllMTggZDBiMzk1YWY1NmE4MWYzNDcxNTU4YWQ3ZWJkYTMyZDY=\n
        < 235 2.7.0 Authentication successful\r\n
        > MAIL FROM:<[email protected]>\n
        < 250 2.1.0 Ok\r\n
        > RCPT TO:<[email protected]>\n
        < 250 2.1.5 Ok\r\n
        > DATA\n
        < 354 End data with <CR><LF>.<CR><LF>\r\n
        > .\n
        < 250 OK queued as 6ffaf3f2-b351-485c-bb27-a4b8230d873b\r\n
        """
    }
  }
  +data: array:1 [
    "message" => Illuminate\Mail\Message^ {#5394
      #message: Symfony\Component\Mime\Email^ {#5231}
      #embeddedFiles: []
    }
  ]
}

But I feel stuck, I want to know how to get the response where I cant get the status of a given email like in this example or how do I get the data json response from MailJet like this one:

{
    "Sent": [
        {
            "Email": "[email protected]",
            "MessageID": 1234567890987654400,
            "MessageUUID": "1ab23cd4-e567-8901-2345-6789f0gh1i2j"
        }
    ]
}

to track the email status? any ideas?

Pavis answered 9/3, 2022 at 22:10 Comment(2)
According to the debug information, the message was dispatched to Mailjet to be delivered. The message uuid appears to be the one in the debug information i.e 6ffaf3f2-b351-485c-bb27-a4b8230d873b. If you need to track that the message was finally delivered by Mailjet, you can set your own custom id in the email headers and use the REST API to get the message status with Mailjet.Mandell
Also, if you need to track email delivery by Mailjet, I would suggest using their REST API integration over SMTP anyway.Mandell

© 2022 - 2024 — McMap. All rights reserved.