-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] add File transport #31947
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
[Mailer] add File transport #31947
Conversation
Hum, I'm not sure how to make it working on Windows since Any ideas? |
Status: Needs review |
PR has been rebased and conflicts resolved. |
Travis/AppVeyor failures are unrelated I think. |
Status: Needs review I've just updated the way we pass a path in order to be compatible with Windows, since Before:
After: MAILER_URL=file://null?path=%kernel.project_dir%/var/emails Travis & AppVeyor failures are still unrelated. |
I've resolved conflicts and squashed everything. EDIT: this travis failure seems to be unrelated. |
Nice to see that you've adopted PR to changes introduced in #31946 .
You should use urls like |
protected function doSend(SentMessage $message): void | ||
{ | ||
$file = $this->path.'/'.uniqid().'.message'; | ||
$serializedMessage = serialize($message); |
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.
How integration test will looks like? Why not save in .eml
format?
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.
I didn't know about .eml
files. In my project, we exposed a endpoint only available in dev/test env that list *.message
file and which display message details like from, to, subject and body. It was consumed by Cypress and it worked well.
But if it can be easily parsed with PHP or JS, why not.
Indeed that better, but it means there is no actual solution to make it usable in Windows with a symfony parameter like this |
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Add message events logger | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | refs #31592, refs #32409, refs #31947, refs #31747 | License | MIT | Doc PR | n/a To allow testing emails and for the web profiler, we need a way to store all sent/queued messages. Commits ------- 7642178 [Mailer] added message events logger
I think that testing emails is orthogonal to the transport. See #32930 for an implementation that allows to receive the email AND test it at the same time in functional tests. |
If you use PHPUnit for functional tests yes, but I'm actually using Cypress (JavaScript) for E2E tests (like a password-reset functionality + email). That's why it was nice to have emails persisted in the filesystem (or somewhere else in fact), with a Symfony controller for displaying sent emails, Cypress were actually able to see them (and click on a button inside the mail, for example). But since #31946 has been merged, I will be able to re-implement the file transport. |
…for the Mailer (fabpot) This PR was merged into the 4.4 branch. Discussion ---------- [Mailer][Mime] Add PHPUnit constraints and assertions for the Mailer | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | refs #31592, closes #32409, closes #31947, closes #31747, closes #30850 | License | MIT | Doc PR | n/a This PR introduces PHPUnit constraints and assertions to ease testing emails in functional tests: ```php <?php namespace App\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class MailerAssertionsTraitsTest extends WebTestCase { public function testSomething() { $client = static::createClient(); $client->request('GET', '/'); $this->assertEmailCount(2); $this->assertEmailIsQueued($this->getMailerEvent(0)); $email = $this->getMailerMessage(0); $this->assertEmailHasHeader($email, 'To'); $this->assertEmailHeaderSame($email, 'To', 'fabien@symfony.com'); $this->assertEmailTextBodyContains($email, 'Bar'); $this->assertEmailHtmlBodyContains($email, 'Foo'); $this->assertEmailAttachementCount($email, 1); } } ``` Commits ------- 23f237b added PHPUnit constraints and assertions for the Mailer
This PR add the file transport to the Mailer component which is useful when running integrations tests.
I've taken this idea from SwiftMailer, but without the spool behavior. It just saves messages to the filesystem and nothing else.
It's supposed to be used like this:
Sent message will now be saved in the directory
%kernel.project_dir%/var/emails
, in a.message
file.What do you think about it?
Thanks!