MailerDeliveryEvent example

<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, 'G9Bn5sl1TC6nu79C8C0bwg', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521233195.375624));
$wh->setReason('No Such User Here');

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '13792286917004336', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('bounce@mailjet.com');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1430812195));
$wh->setReason('mailjet');
$wh->setTags(['helloworld']);
$wh->setMetadata(['Payload' => '']);

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '<202305311400.29297141656@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['tag1', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685541608));
$wh->setReason('blocked : due to unsubscribed user');

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DELIVERED, 'CPgfbmQMTCKtHW6uIWtuVe', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521472262.908181));
$wh->setReason('OK');

return $wh;
public function convert(array $payload): AbstractMailerEvent
    {
        if (\in_array($payload['event']['accepted', 'rejected', 'delivered', 'failed', 'blocked'], true)) {
            $name = match ($payload['event']) {
                'accepted' => MailerDeliveryEvent::RECEIVED,
                'rejected' => MailerDeliveryEvent::DROPPED,
                'delivered' => MailerDeliveryEvent::DELIVERED,
                'blocked' => MailerDeliveryEvent::DROPPED,
                'failed' => $this->matchFailedEvent($payload),
            };

            $event = new MailerDeliveryEvent($name$payload['id']$payload);
            // reason is only available on failed messages             $event->setReason($this->getReason($payload));
        } else {
            $name = match ($payload['event']) {
                'clicked' => MailerEngagementEvent::CLICK,
                'unsubscribed' => MailerEngagementEvent::UNSUBSCRIBE,
                'opened' => MailerEngagementEvent::OPEN,
                'complained' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['id']$payload);
        }
$name = match ($payload['event']) {
                'request' => MailerDeliveryEvent::RECEIVED,
                'deferred' => MailerDeliveryEvent::DEFERRED,
                'delivered' => MailerDeliveryEvent::DELIVERED,
                'soft_bounce' => MailerDeliveryEvent::BOUNCE,
                'hard_bounce' => MailerDeliveryEvent::BOUNCE,
                'invalid_email' => MailerDeliveryEvent::DROPPED,
                'blocked' => MailerDeliveryEvent::DROPPED,
                'error' => MailerDeliveryEvent::DROPPED,
            };

            $event = new MailerDeliveryEvent($name$payload['message-id']$payload);
        } else {
            $name = match ($payload['event']) {
                'click' => MailerEngagementEvent::CLICK,
                'unsubscribed' => MailerEngagementEvent::UNSUBSCRIBE,
                'unique_opened' => MailerEngagementEvent::OPEN,
                'opened' => MailerEngagementEvent::OPEN,
                'proxy_open' => MailerEngagementEvent::OPEN,
                'complaint' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['message-id']$payload);
        }
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));
$wh->setReason("server is down");

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, 'G9Bn5sl1TC6nu79C8C0bwg', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521233195.375624));
$wh->setReason('Not delivering to previously bounced address');

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DELIVERED, '00000000-0000-0000-0000-000000000000', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true));
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setReason('');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T11:49:27Z'));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DEFERRED, 'Fs7-5t81S2ispqxqDw2U4Q', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521472262.908181));
$wh->setReason("4.2.2 The email account that you tried to reach is over quota. Please direct\n4.2.2 the recipient to\n4.2.2 https://support.example.com/mail/?p=422");

return $wh;
final class SendgridPayloadConverter implements PayloadConverterInterface
{
    public function convert(array $payload): AbstractMailerEvent
    {
        if (\in_array($payload['event']['processed', 'delivered', 'bounce', 'dropped', 'deferred'], true)) {
            $name = match ($payload['event']) {
                'processed', 'delivered' => MailerDeliveryEvent::DELIVERED,
                'dropped' => MailerDeliveryEvent::DROPPED,
                'deferred' => MailerDeliveryEvent::DEFERRED,
                'bounce' => MailerDeliveryEvent::BOUNCE,
            };
            $event = new MailerDeliveryEvent($name$payload['sg_message_id']$payload);
            $event->setReason($payload['reason'] ?? '');
        } else {
            $name = match ($payload['event']) {
                'click' => MailerEngagementEvent::CLICK,
                'unsubscribe' => MailerEngagementEvent::UNSUBSCRIBE,
                'open' => MailerEngagementEvent::OPEN,
                'spamreport' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['unsubscribe'])),
            };
            $event = new MailerEngagementEvent($name$payload['sg_message_id']$payload);
        }

        
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '104427216766056450', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('event-bounce@yahoo.fr');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685525050));
$wh->setReason('policy issue');
$wh->setTags(['helloworld']);
$wh->setMetadata(['Payload' => '']);

return $wh;
final class MailjetPayloadConverter implements PayloadConverterInterface
{
    public function convert(array $payload): AbstractMailerEvent
    {
        if (\in_array($payload['event']['bounce', 'sent', 'blocked'], true)) {
            $name = match ($payload['event']) {
                'bounce' => MailerDeliveryEvent::BOUNCE,
                'sent' => MailerDeliveryEvent::DELIVERED,
                'blocked' => MailerDeliveryEvent::DROPPED,
            };

            $event = new MailerDeliveryEvent($name$payload['MessageID']$payload);
            $event->setReason($this->getReason($payload));
        } else {
            $name = match ($payload['event']) {
                'click' => MailerEngagementEvent::CLICK,
                'open' => MailerEngagementEvent::OPEN,
                'spam' => MailerEngagementEvent::SPAM,
                'unsub' => MailerEngagementEvent::UNSUBSCRIBE,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['MessageID']$payload);
        }

        
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '00000000-0000-0000-0000-000000000000', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true));
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['Test']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setReason('The server was unable to deliver your message (ex: unknown user, mailbox not found).');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:19Z'));

return $wh;
Home | Imprint | This part of the site doesn't use cookies.