Hello,
I have set up an application for my company to send mass notification out to employees. I was using SMTP but have switched to the API. Most other applications when sending to an API there is usually a response but I am not sure how to capture that in Laravel. In particular, I am looking for the message id so I can store the log and receive status updates. However, all the send methods of MAIL are void and don't return anything - unless I am missing something.
@Braunson
I plan on using the webhook. The problem is when I send the message and insert the record into the database, when an update for a message comes into the webhook URL, how do I determine which message the update is for?
I know mailgun assigns a unique ID to every message, but how do I capture that when the message is sent?
public function __construct(MessageSending $event)
{
logger()->info('Message ID: ' . $event->message->getId());
// Record to your DB for reference
}
If you need to pass any data from the mailable like a reference to a contact, you can add it as a header in the Mailable and retrieve the header in the listener or set a public parameter in the Mailable class and you should have access to it from the listener. I used this in a previous project where we had to log emails going out plus append headers to the email and when MG called our webhook we could read the message ID and/or headers to retrieve the record in the database for that specific email to update the status, etc.
@Sinnbeck
I think that gets the the ID from Swift and I know I can send that along with the message and when status updates come in, mailgun will send that back. I can definitely do it that way.
Would you happen to know of a tutorial where that is demonstrated.
@sinnbeck I am going to give it a try to see if I can get it. I am just having a hard time testing the webhook because the test application is not accessible from the web.