WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.086 --> 00:00:03.076 align:middle
Time to test-drive the Mailtrap webhook!

00:00:03.196 --> 00:00:07.226 align:middle
First, we need to switch our development
environment to send in production again.

00:00:07.886 --> 00:00:16.326 align:middle
In .env.local, switch to your production
Mailtrap MAILER_DSN and in config/services.yaml,

00:00:16.596 --> 00:00:20.716 align:middle
make sure the global_from_email's domain
is the one you configured with Mailtrap.

00:00:22.766 --> 00:00:27.686 align:middle
Over in Mailtrap, go to "Settings" &gt;
"Webhooks" and click "Create New Webhook".

00:00:27.826 --> 00:00:30.376 align:middle
First thing we need is a Webhook URL.

00:00:30.606 --> 00:00:36.406 align:middle
Hmm, this needs to be /webhook/mailtrap
but it needs to be an absolute URL.

00:00:37.066 --> 00:00:40.826 align:middle
In production, this wouldn't be a problem:
it would be your production domain.

00:00:41.246 --> 00:00:43.006 align:middle
In development, it's a bit trickier.

00:00:43.336 --> 00:00:46.696 align:middle
We can't just use the URL the
Symfony CLI server gives us...

00:00:46.836 --> 00:00:51.016 align:middle
Somehow we need to expose our
local Symfony server to the public.

00:00:51.246 --> 00:00:54.426 align:middle
And there's a neat tool that
does exactly this: ngrok.

00:00:55.186 --> 00:01:00.626 align:middle
Create a free account, log in, and follow the
instructions to configure the ngrok CLI client.

00:01:01.516 --> 00:01:04.186 align:middle
Over in the terminal, restart
with Symfony webserver:

00:01:04.476 --> 00:01:07.676 align:middle
symfony server:stop Oh, it isn't running.

00:01:07.676 --> 00:01:15.146 align:middle
Start it with: symfony serve -d This is
the URL we need to expose, copy it and run:

00:01:15.896 --> 00:01:19.816 align:middle
ngrok http &lt;paste-url&gt; Paste
the URL, and hit enter.

00:01:19.976 --> 00:01:21.136 align:middle
Wormhole open!

00:01:21.506 --> 00:01:24.736 align:middle
This crazy looking "Forwarding"
URL is the public URL.

00:01:25.316 --> 00:01:27.146 align:middle
Copy and paste it into your browser.

00:01:29.186 --> 00:01:31.586 align:middle
This warning just lets you know
you're running through a tunnel.

00:01:32.356 --> 00:01:34.056 align:middle
Click "Visit Site" to see your app.

00:01:34.896 --> 00:01:41.186 align:middle
Cool! Back in Mailtrap, paste this URL
and add /webhook/mailtrap to the end.

00:01:42.706 --> 00:01:45.156 align:middle
For "Select Stream", choose "Transactional".

00:01:45.156 --> 00:01:48.646 align:middle
For "Select Domain", choose
your configured Mailtrap domain.

00:01:49.166 --> 00:01:51.806 align:middle
Go nuts and select all events, then "Save".

00:01:53.636 --> 00:01:56.446 align:middle
Go back into the new webhook
and click "Run Test".

00:01:58.086 --> 00:02:01.586 align:middle
Webhook URL test completed
successfully That's a good sign!

00:02:02.226 --> 00:02:05.676 align:middle
Remember in our EmailEventConsumer,
we're just dumping the event?

00:02:05.866 --> 00:02:10.146 align:middle
Since hitting the webhook happens behind
the scenes, we can't see the dump...

00:02:10.606 --> 00:02:11.306 align:middle
or can we?

00:02:12.016 --> 00:02:17.706 align:middle
In a new terminal run: symfony console
server:dump This hooks into our app

00:02:17.706 --> 00:02:19.826 align:middle
and any dumps will be output here live.

00:02:20.066 --> 00:02:26.616 align:middle
Clever! In your browser, book a trip, remember
to use a real email address (but not mine!)

00:02:30.986 --> 00:02:31.976 align:middle
Moment of truth!

00:02:32.236 --> 00:02:35.206 align:middle
Back in the terminal running
the dump server, wait a bit...

00:02:35.996 --> 00:02:37.446 align:middle
Alright! We have a dump!

00:02:37.446 --> 00:02:38.586 align:middle
Scroll up a bit...

00:02:38.976 --> 00:02:41.456 align:middle
This is a MailerDeliveryEvent for delivered.

00:02:42.256 --> 00:02:47.826 align:middle
We see the internal ID Mailtrap assigned,
the raw payload, date, recipient email,

00:02:48.106 --> 00:02:49.856 align:middle
even our custom metadata and tag.

00:02:49.856 --> 00:02:52.336 align:middle
Let's try an engagement event!

00:02:53.096 --> 00:02:55.196 align:middle
In your email client, open the email.

00:02:57.686 --> 00:03:00.486 align:middle
Back in the dump server terminal, wait a bit...

00:03:00.486 --> 00:03:02.076 align:middle
and boom! Another event!

00:03:03.516 --> 00:03:06.556 align:middle
This time, it's a MailerEngagementEvent
for open.

00:03:06.776 --> 00:03:07.656 align:middle
This is cool!

00:03:08.676 --> 00:03:11.196 align:middle
Alright space cadets, that's it for this course!

00:03:11.376 --> 00:03:16.006 align:middle
We managed to cover almost all of Symfony
Mailer features without SPAM'ing our users.

00:03:16.086 --> 00:03:18.816 align:middle
Win! 'Til next time, happy coding!

