-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[9.x] Add Symfony Mailer to Upgrade Guide #7454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Jubeki
wants to merge
18
commits into
laravel:master
from
Jubeki:add-symfony-mailer-to-upgrade-guide
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b599b96
Add Symfony Mailer to Upgrade Guide
Jubeki c93cece
Add example for updated Illuminate\Mail\Message
Jubeki 71ce90b
Add example for Stream Options for SMTP transport
Jubeki 45eab6a
Add methods which need to be renamed from Swift to Symfony
Jubeki f09511f
Add methods which need to be renamed from Swift to Symfony
Jubeki 7554b02
Fix initial paragraph
Jubeki 5eaa110
Add empty line
Jubeki 3ca6255
Wrap Classes in Code aposotrophes
Jubeki f8a96d1
Add empty line and fix code in sentence
Jubeki 6be7742
Add empty line
Jubeki 867da4a
Add empty line and end sentence correctly
Jubeki cc88fdc
Add empty line and fix typo
Jubeki b66564c
Add empty line
Jubeki f3c3aee
Add empty line
Jubeki 283e32f
Add empty line and fix typo
Jubeki db34d66
Add empty line
Jubeki 8ce23e5
Fix code example spacing
Jubeki cfdf664
Fix typo and Add empty line
Jubeki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,146 @@ The `storagePath` method of the `Illuminate\Contracts\Foundation\Application` in | |
|
||
public function storagePath($path = ''); | ||
|
||
<a name="mail"></a> | ||
|
||
<a name="symfony-mailer"></a> | ||
#### Symfony Mailer | ||
|
||
**Likelihood Of Impact: High** | ||
|
||
SwiftMailer is discontinued as of December 2021 and was therefore replaced with Symfony Mailer 6.0 (See https://symfony.com/blog/the-end-of-swiftmailer). Because of this, SwiftMailer plugins and transports will no longer work with the new implementation. | ||
|
||
##### Updated Content Methods | ||
|
||
`send`, `html`, `text` & `plain` don't return the number of recipients anymore but an instance of `Illuminate\Mail\SentMessage` which contains the `Symfony\Component\Mailer\SentMessage` instance | ||
|
||
##### Renamed Swift methods to Symfony | ||
|
||
All Swift methods were renamed to an equivalent with Symfony in the method name. For example: | ||
|
||
// BEFORE | ||
$this->withSwiftMessage(function ($message) { | ||
$message->getHeaders()->addTextHeader( | ||
'Custom-Header', 'Header Value' | ||
); | ||
}); | ||
|
||
// AFTER | ||
use Symfony\Component\Mime\Email; | ||
|
||
$this->withSymfonyMessage(function (Email $message) { | ||
$message->getHeaders()->addTextHeader( | ||
'Custom-Header', 'Header Value' | ||
); | ||
}); | ||
|
||
Please also take a look at the [Symfony Mailer Docs](https://symfony.com/doc/6.0/mailer.html#creating-sending-messages) for all possible interactions with the Email message. | ||
|
||
Here is a list of all Methods which need to be renamed if they are used: | ||
|
||
Message::getSwiftMessage(); | ||
Message::getSymfonyMessage(); | ||
|
||
Mailable::withSwiftMessage($callback); | ||
Mailable::withSymfonyMessage($callback); | ||
|
||
MailMessage::withSwiftMessage($callback); | ||
MailMessage::withSymfonyMessage($callback); | ||
|
||
Mailer::getSwiftMailer(); | ||
Mailer::getSymfonyTransport(); | ||
|
||
Mailer::setSwiftMailer($swift); | ||
Mailer::setSymfonyTransport(TransportInterface $transport); | ||
|
||
MailManager::createTransport($config); | ||
MailManager::createSymfonyTransport($config); | ||
|
||
##### `Illuminate\Mail\Message` | ||
|
||
The `Illuminate\Mail\Message` class now contains an instance of `Symfony\Component\Mime\Email` instead of `Swift_Message` so all forwarding calls in user-land will need to be updated. Here are some examples which were possible with SwiftMailer but are not possible anymore with Symfony Mailer (most people are probably using the Laravel style already): | ||
|
||
// IF YOU USED THIS | ||
$message | ||
->setFrom('[email protected]') | ||
->setTo('[email protected]') | ||
->setSubject("Order Shipped") | ||
->setBody( | ||
'<h1>HTML email</h1><p>Shows HTML tags if the client supports it.</p>', | ||
'text/html' | ||
) | ||
->addPart( | ||
'Some Plain text in the email', | ||
'text/plain' | ||
); | ||
|
||
// YOU NEED TO CHANGE IT TO | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->subject("Order Shipped") | ||
->html('<h1>HTML email</h1><p>Shows HTML tags if the client supports it.</p>') | ||
->text('Some Plain text in the email'); | ||
|
||
##### Removed `auth_mode` for SMTP | ||
|
||
Setting the `auth_mode` in the mail config was removed, because the authentication mode can be automatically negotiated between the Mailer and the SMTP server. | ||
|
||
##### Failed recipients | ||
|
||
It's no longer possible to get a list of failed recipients. Instead, if an email is failed to send, and exception will be thrown. | ||
|
||
##### Stream Options for SMTP transport | ||
|
||
Setting stream options for the SMTP transport can no longer be done through an smtp key. Instead you need to set the options directly in the config. For example, when disabling TLS peer verification in `config/mail.php`: | ||
|
||
'smtp' => [ | ||
// BEFORE | ||
'stream' => [ | ||
'ssl' => [ | ||
'verify_peer' => false, | ||
], | ||
], | ||
|
||
// AFTER | ||
'verify_peer' => false, | ||
], | ||
|
||
> {note} It is generally not advised to disable the Verification of SSL-Certificates because it introduces the possibiliets of Man-in-the-Middle attacks. | ||
|
||
For more options you can take a look at the [Symfony Mailer Docs](https://symfony.com/doc/6.0/mailer.html#transport-setup) | ||
|
||
##### Generated Messages ID's | ||
|
||
SwiftMailer offered the ability to set a custom domain to generate Message ID's through `mime.idgenerator.idright`. This is no longer possible with Symfony Mailer. Instead, Symfony Mailer will automatically generate a Message ID based on the sender and add it to a message automatically. | ||
|
||
##### Removed Force Reconnection | ||
|
||
It is no longer possible to force a reconnection (for example when the mailer is running through a daemon process). Instead, Symfony Mailer will properly attempt to reconnect the transport itself and error out if that fails. | ||
|
||
##### Driver / Transport Prerequisites | ||
|
||
`guzzlehttp/guzzle` can be removed if wanted (Still required to use with the HTTP Client and the ping methods on the scheduler). Symfony API mail transport will utilize `symfony/http` instead. | ||
|
||
###### SES | ||
|
||
`aws/aws-sdk-php` is not needed for SES Transport anymore and can be removed if wanted (Still required to use with the SQS queue driver and DynamoDb failed job storage). To continue using the SES Mailer you are required to use the underlying Symfony Amazon Mailer: | ||
|
||
composer require symfony/amazon-mailer | ||
|
||
###### Mailgun | ||
|
||
To continue using the Mailgun Mailer you are required to use the underlying Symfony Mailgun Mailer: | ||
|
||
composer require symfony/mailgun-mailer | ||
|
||
###### Postmark | ||
|
||
`wildbit/swiftmailer-postmark` needs to be removed because Laravel moved from SwiftMailer to Symfony Mailer. To continue using Postmark Mailer you are required to use the underlying Symfony Postmark Mailer: | ||
|
||
composer require symfony/postmark-mailer | ||
|
||
<a name="queue"></a> | ||
### Queue | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylorotwell
A
TransportExceptionInterface
will be thrown if the email could not be send.https://symfony.com/doc/current/mailer.html#handling-sending-failures
The failed recipients are an artifact of
Swift_RfcComplianceException
, thus holds the invalid address (you can validate this yourself as well, before sending)symfony/symfony#33812
It would probably be better to word it something like this: