From 7d388c33791e183d9680ba79d7214c3dc98589f6 Mon Sep 17 00:00:00 2001 From: Julius Kiekbusch Date: Sun, 12 Sep 2021 19:46:37 +0200 Subject: [PATCH 1/5] Update from Swift Mailer to Symfony Mailer --- contracts.md | 2 +- mail.md | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/contracts.md b/contracts.md index 5c27ba27123..635c7eba54c 100644 --- a/contracts.md +++ b/contracts.md @@ -11,7 +11,7 @@ Laravel's "contracts" are a set of interfaces that define the core services provided by the framework. For example, an `Illuminate\Contracts\Queue\Queue` contract defines the methods needed for queueing jobs, while the `Illuminate\Contracts\Mail\Mailer` contract defines the methods needed for sending e-mail. -Each contract has a corresponding implementation provided by the framework. For example, Laravel provides a queue implementation with a variety of drivers, and a mailer implementation that is powered by [SwiftMailer](https://swiftmailer.symfony.com/). +Each contract has a corresponding implementation provided by the framework. For example, Laravel provides a queue implementation with a variety of drivers, and a mailer implementation that is powered by [Symfony Mailer](https://symfony.com/doc/6.0/mailer.html). All of the Laravel contracts live in [their own GitHub repository](https://github.com/illuminate/contracts). This provides a quick reference point for all available contracts, as well as a single, decoupled package that may be utilized when building packages that interact with Laravel services. diff --git a/mail.md b/mail.md index 1ae47e86b1f..9692db84a56 100644 --- a/mail.md +++ b/mail.md @@ -10,7 +10,7 @@ - [View Data](#view-data) - [Attachments](#attachments) - [Inline Attachments](#inline-attachments) - - [Customizing The SwiftMailer Message](#customizing-the-swiftmailer-message) + - [Customizing The Symfony Message](#customizing-the-symfony-message) - [Markdown Mailables](#markdown-mailables) - [Generating Markdown Mailables](#generating-markdown-mailables) - [Writing Markdown Messages](#writing-markdown-messages) @@ -27,7 +27,7 @@ ## Introduction -Sending email doesn't have to be complicated. Laravel provides a clean, simple email API powered by the popular [SwiftMailer](https://swiftmailer.symfony.com/) library. Laravel and SwiftMailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and `sendmail`, allowing you to quickly get started sending mail through a local or cloud based service of your choice. +Sending email doesn't have to be complicated. Laravel provides a clean, simple email API powered by using the popular [Symfony Mailer](https://symfony.com/doc/6.0/mailer.html) component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and `sendmail`, allowing you to quickly get started sending mail through a local or cloud based service of your choice. ### Configuration @@ -39,14 +39,16 @@ Within your `mail` configuration file, you will find a `mailers` configuration a ### Driver / Transport Prerequisites -The API based drivers such as Mailgun and Postmark are often simpler and faster than sending mail via SMTP servers. Whenever possible, we recommend that you use one of these drivers. All of the API based drivers require the Guzzle HTTP library, which may be installed via the Composer package manager: - - composer require guzzlehttp/guzzle +The API based drivers such as Mailgun and Postmark are often simpler and faster than sending mail via SMTP servers. Whenever possible, we recommend that you use one of these drivers. #### Mailgun Driver -To use the Mailgun driver, first install the Guzzle HTTP library. Then, set the `default` option in your `config/mail.php` configuration file to `mailgun`. Next, verify that your `config/services.php` configuration file contains the following options: +To use the Mailgun driver, install Symfony's Mailgun Mailer transport via Composer: + + composer require symfony/mailgun-mailer + +Next set the `default` option in your `config/mail.php` configuration file to `mailgun`. Next, verify that your `config/services.php` configuration file contains the following options: 'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), @@ -64,11 +66,11 @@ If you are not using the United States [Mailgun region](https://documentation.ma #### Postmark Driver -To use the Postmark driver, install Postmark's SwiftMailer transport via Composer: +To use the Postmark driver, install Symfony's Postmark Mailer transport via Composer: - composer require wildbit/swiftmailer-postmark + composer require symfony/postmark-mailer -Next, install the Guzzle HTTP library and set the `default` option in your `config/mail.php` configuration file to `postmark`. Finally, verify that your `config/services.php` configuration file contains the following options: +Next set the `default` option in your `config/mail.php` configuration file to `postmark`. Finally, verify that your `config/services.php` configuration file contains the following options: 'postmark' => [ 'token' => env('POSTMARK_TOKEN'), @@ -86,10 +88,10 @@ This way you are also able to set up multiple Postmark mailers with different me #### SES Driver -To use the Amazon SES driver you must first install the Amazon AWS SDK for PHP. You may install this library via the Composer package manager: +To use the SES driver, install Symfony's Amazon Mailer transport via Composer: ```bash -composer require aws/aws-sdk-php +composer require symfony/amazon-mailer ``` Next, set the `default` option in your `config/mail.php` configuration file to `ses` and verify that your `config/services.php` configuration file contains the following options: @@ -420,10 +422,10 @@ If you already have a raw image data string you wish to embed into an email temp - -### Customizing The SwiftMailer Message + +### Customizing The Symfony Message -The `withSwiftMessage` method of the `Mailable` base class allows you to register a closure which will be invoked with the SwiftMailer message instance before sending the message. This gives you an opportunity to deeply customize the message before it is delivered: +The `withSymfonyMessage` method of the `Mailable` base class allows you to register a closure which will be invoked with the Symfony Message instance before sending the message. This gives you an opportunity to deeply customize the message before it is delivered: /** * Build the message. @@ -434,7 +436,7 @@ The `withSwiftMessage` method of the `Mailable` base class allows you to registe { $this->view('emails.orders.shipped'); - $this->withSwiftMessage(function ($message) { + $this->withSymfonyMessage(function ($message) { $message->getHeaders()->addTextHeader( 'Custom-Header', 'Header Value' ); From 1e39e96d46180c3d7d91d4f97d6673357252f47e Mon Sep 17 00:00:00 2001 From: Julius Kiekbusch Date: Sun, 12 Sep 2021 19:57:53 +0200 Subject: [PATCH 2/5] Fix typo --- mail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail.md b/mail.md index 9692db84a56..addc44fc932 100644 --- a/mail.md +++ b/mail.md @@ -27,7 +27,7 @@ ## Introduction -Sending email doesn't have to be complicated. Laravel provides a clean, simple email API powered by using the popular [Symfony Mailer](https://symfony.com/doc/6.0/mailer.html) component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and `sendmail`, allowing you to quickly get started sending mail through a local or cloud based service of your choice. +Sending email doesn't have to be complicated. Laravel provides a clean, simple email API powered by the popular [Symfony Mailer](https://symfony.com/doc/6.0/mailer.html) component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and `sendmail`, allowing you to quickly get started sending mail through a local or cloud based service of your choice. ### Configuration From 3372d569f78b44518211676b3102590f57809f01 Mon Sep 17 00:00:00 2001 From: Julius Kiekbusch Date: Tue, 14 Sep 2021 11:43:44 +0200 Subject: [PATCH 3/5] Add Typehint to withSymfonyMessage --- mail.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mail.md b/mail.md index addc44fc932..d2e06698978 100644 --- a/mail.md +++ b/mail.md @@ -427,6 +427,8 @@ If you already have a raw image data string you wish to embed into an email temp The `withSymfonyMessage` method of the `Mailable` base class allows you to register a closure which will be invoked with the Symfony Message instance before sending the message. This gives you an opportunity to deeply customize the message before it is delivered: + use Illuminate\Mail\Message; + /** * Build the message. * @@ -436,7 +438,7 @@ The `withSymfonyMessage` method of the `Mailable` base class allows you to regis { $this->view('emails.orders.shipped'); - $this->withSymfonyMessage(function ($message) { + $this->withSymfonyMessage(function (Message $message) { $message->getHeaders()->addTextHeader( 'Custom-Header', 'Header Value' ); From 51ada9c8ed90704837509cdc7682df8dba6a82bc Mon Sep 17 00:00:00 2001 From: Julius Kiekbusch Date: Tue, 14 Sep 2021 11:50:59 +0200 Subject: [PATCH 4/5] Fix withSymfonyMessage typehint --- mail.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mail.md b/mail.md index d2e06698978..4e1d7c2f71c 100644 --- a/mail.md +++ b/mail.md @@ -427,7 +427,7 @@ If you already have a raw image data string you wish to embed into an email temp The `withSymfonyMessage` method of the `Mailable` base class allows you to register a closure which will be invoked with the Symfony Message instance before sending the message. This gives you an opportunity to deeply customize the message before it is delivered: - use Illuminate\Mail\Message; + use Symfony\Component\Mime\Email; /** * Build the message. @@ -438,7 +438,7 @@ The `withSymfonyMessage` method of the `Mailable` base class allows you to regis { $this->view('emails.orders.shipped'); - $this->withSymfonyMessage(function (Message $message) { + $this->withSymfonyMessage(function (Email $message) { $message->getHeaders()->addTextHeader( 'Custom-Header', 'Header Value' ); From 14c8b61dca3d56764b5e4d73227d88fbf487d6b6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 14 Sep 2021 14:02:02 -0500 Subject: [PATCH 5/5] formatting --- mail.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mail.md b/mail.md index 4e1d7c2f71c..14565bec954 100644 --- a/mail.md +++ b/mail.md @@ -48,7 +48,7 @@ To use the Mailgun driver, install Symfony's Mailgun Mailer transport via Compos composer require symfony/mailgun-mailer -Next set the `default` option in your `config/mail.php` configuration file to `mailgun`. Next, verify that your `config/services.php` configuration file contains the following options: +Next, set the `default` option in your application's `config/mail.php` configuration file to `mailgun`. After configuring your application's default mailer, verify that your `config/services.php` configuration file contains the following options: 'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), @@ -70,7 +70,7 @@ To use the Postmark driver, install Symfony's Postmark Mailer transport via Comp composer require symfony/postmark-mailer -Next set the `default` option in your `config/mail.php` configuration file to `postmark`. Finally, verify that your `config/services.php` configuration file contains the following options: +Next, set the `default` option in your application's `config/mail.php` configuration file to `postmark`. After configuring your application's default mailer, verify that your `config/services.php` configuration file contains the following options: 'postmark' => [ 'token' => env('POSTMARK_TOKEN'),