I am trying to send email using AWS SES service and the Laravel Mail class (Illuminate\Support\Facades\Mail
).
I would like to set to the ConfigurationSetName
to be able to recieve notifications via AWS SNS.
At the moment, I am using the Laravel Mail class using SES and it is working but not the notifications.
Is there any way to do this? Or do I have to use the SesClient always to assign the ConfigurationSetName
?
According to the AWS Documentation, you can specify the X-SES-CONFIGURATION-SET
header on the email.
From a Laravel perspective, the easiest way is to specify the headers to be sent right from your Mailable:
public function build()
{
$this->markdown('emails.creditcard.added');
$this->withSwiftMessage(function ($message) {
$message->getHeaders()
->addTextHeader('X-SES-CONFIGURATION-SET', '####');
});
}
You could also do it using the Mail Facade, since it has an underlying Swift_Message
instance. For example:
Mail::send('emails.creditcard.added', [], function ($message) use($user) {
$message->to($user->email)
->getSwiftMessage()
->getHeaders()
->addTextHeader('X-SES-CONFIGURATION-SET', '####');
});
If you want to add this header to all emails, you could also listen to the Illuminate\Mail\Events\MessageSending
event and add the headers from there.
public function handle(MessageSending $event)
{
$headers = $event->message->getHeaders();
$headers->addTextHeader('X-SES-CONFIGURATION-SET', '####');
}
I also verified that it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With