{"id":19300045,"url":"https://github.com/kirschbaum-development/mail-intercept","last_synced_at":"2025-05-16T02:09:10.805Z","repository":{"id":36477158,"uuid":"226373598","full_name":"kirschbaum-development/mail-intercept","owner":"kirschbaum-development","description":"A testing package for intercepting mail sent from Laravel","archived":false,"fork":false,"pushed_at":"2025-03-13T02:06:36.000Z","size":222,"stargazers_count":109,"open_issues_count":1,"forks_count":8,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-10T12:48:33.546Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirschbaum-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-06T16:59:36.000Z","updated_at":"2025-03-13T02:04:01.000Z","dependencies_parsed_at":"2024-06-20T21:50:06.470Z","dependency_job_id":"0b6e46c2-ad99-493e-8443-32d5dcb91c0c","html_url":"https://github.com/kirschbaum-development/mail-intercept","commit_stats":{"total_commits":63,"total_committers":7,"mean_commits":9.0,"dds":"0.17460317460317465","last_synced_commit":"952ae68511d0123d8bff6a9a69c8d4791032ef25"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Fmail-intercept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Fmail-intercept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Fmail-intercept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Fmail-intercept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirschbaum-development","download_url":"https://codeload.github.com/kirschbaum-development/mail-intercept/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453655,"owners_count":22073617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:13:30.614Z","updated_at":"2025-05-16T02:09:10.747Z","avatar_url":"https://github.com/kirschbaum-development.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Mail Intercept banner](screenshots/banner.jpg)\n\n# Laravel Mail Intercept\n### A testing package for intercepting mail sent from Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kirschbaum-development/mail-intercept.svg)](https://packagist.org/packages/kirschbaum-development/mail-intercept)\n[![Total Downloads](https://img.shields.io/packagist/dt/kirschbaum-development/mail-intercept.svg)](https://packagist.org/packages/kirschbaum-development/mail-intercept)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cc0749987c38426ebc8b0059c1171e27)](https://www.codacy.com/manual/Kirschbaum/mail-intercept?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=kirschbaum-development/mail-intercept\u0026amp;utm_campaign=Badge_Grade)\n[![Actions Status](https://github.com/kirschbaum-development/mail-intercept/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/mail-intercept/actions)\n\nThis testing suite intercepts Laravel Mail just before they are sent out, allowing all kinds of assertions to be made on the actual emails themselves.\n\nMail isn't faked here. You get to inspect the actual mail ensuring you are sending exactly what you want!\n\n## Requirements\n\n| Laravel Version | Mail Intercept Version |\n|:----------------|:-----------------------|\n| 10.x \u0026 11.0     | 1.0.x                  |\n| 9.x             | 0.3.x                  |\n| 8.x and lower   | 0.2.x                  |\n\nPlease note: If you are using `v0.2.x`, please refer to that version's [documentation](https://github.com/kirschbaum-development/mail-intercept/tree/v0.2.x).\n\n## Installation\n\n```bash\ncomposer require kirschbaum-development/mail-intercept --dev\n```\n\n## Usage\n\nNext you can use the `KirschbaumDevelopment\\MailIntercept\\WithMailInterceptor` trait in your test class:\n\n```php\nnamespace Tests;\n\nuse App\\Mail\\TestMail;\nuse Illuminate\\Support\\Facades\\Mail;\nuse Illuminate\\Foundation\\Testing\\WithFaker;\nuse KirschbaumDevelopment\\MailIntercept\\WithMailInterceptor;\n\nclass MailTest extends TestCase\n{\n    use WithFaker;\n    use WithMailInterceptor;\n\n    public function testMail()\n    {\n        $this-\u003einterceptMail();\n\n        $email = $this-\u003efaker-\u003eemail;\n\n        Mail::to($email)-\u003esend(new TestMail());\n\n        $interceptedMail = $this-\u003einterceptedMail()-\u003efirst();\n\n        $interceptedMail-\u003eassertSentTo($email);\n    }\n}\n```\n\nThat's it! Pretty simple, right?!\n\nThere are two ways of accessing the assertions. First is the fluent syntax directly on each intercepted email.\n\n```php\n$interceptedMail-\u003eassertSentTo($email);\n```\n\nThe other way (the older way) is to use the assertions methods made available from the `WithMailInterceptor` trait. Using these methods are fine, but aren't as clean to write.\n\n```php\n$this-\u003eassertMailSentTo($email, $interceptedEmail);\n```\n\nBoth of these assertions do the exact same thing, the fluent one is just much cleaner. See all the available assertion methods below!\n\n### Testing API\n\n```php\n$this-\u003einterceptMail()\n```\n\nThis method MUST be called first, similar to how `Mail::fake()` works. But unlike the mail fake, mail is not faked, it is intercepted.\n\n```php\n$this-\u003einterceptedMail()\n```\n\nThis should be called after `Mail` has been sent, but before your assertions, otherwise you won't have any emails to work with. It returns a `Collection` of emails so you are free to use any of the methods available to a collection.\n\n#### Fluent Assertion Methods\n\n| Assertions                                             | Parameters              |\n|:-------------------------------------------------------|:------------------------|\n| `$intercepted-\u003eassertSentTo($to);`                     | `$to` array, string     |\n| `$intercepted-\u003eassertNotSentTo($to);`                  | `$to` array, string     |\n| `$intercepted-\u003eassertSentFrom($from);`                 | `$from` array, string   |\n| `$intercepted-\u003eassertNotSentFrom($from);`              | `$from` array, string   |\n| `$intercepted-\u003eassertSubject($subject);`               | `$subject` string       |\n| `$intercepted-\u003eassertNotSubject($subject);`            | `$subject` string       |\n| `$intercepted-\u003eassertBodyContainsString($content);`    | `$content` string       |\n| `$intercepted-\u003eassertBodyNotContainsString($content);` | `$content` string       |\n| `$intercepted-\u003eassertRepliesTo($reply);`               | `$reply` array, string  |\n| `$intercepted-\u003eassertNotRepliesTo($reply);`            | `$reply` array, string  |\n| `$intercepted-\u003eassertCc($cc);`                         | `$cc` array, string     |\n| `$intercepted-\u003eassertNotCc($cc);`                      | `$cc` array, string     |\n| `$intercepted-\u003eassertBcc($cc);`                        | `$bcc` array, string    |\n| `$intercepted-\u003eassertNotBcc($cc);`                     | `$bcc` array, string    |\n| `$intercepted-\u003eassertSender($sender);`                 | `$sender` array, string |\n| `$intercepted-\u003eassertNotSender($sender);`              | `$sender` array, string |\n| `$intercepted-\u003eassertReturnPath($returnPath);`         | `$returnPath` string    |\n| `$intercepted-\u003eassertNotReturnPath($returnPath);`      | `$returnPath` string    |\n\n| Content Type Assertions                          |\n|:-------------------------------------------------|\n| `$intercepted-\u003eassertIsPlain();`                 |\n| `$intercepted-\u003eassertIsNotPlain();`              |\n| `$intercepted-\u003eassertHasPlainContent();`         |\n| `$intercepted-\u003eassertDoesNotHavePlainContent();` |\n| `$intercepted-\u003eassertIsHtml();`                  |\n| `$intercepted-\u003eassertIsNotHtml();`               |\n| `$intercepted-\u003eassertHasHtmlContent();`          |\n| `$intercepted-\u003eassertDoesNotHaveHtmlContent();`  |\n| `$intercepted-\u003eassertIsAlternative();`           |\n| `$intercepted-\u003eassertIsNotAlternative();`        |\n| `$intercepted-\u003eassertIsMixed();`                 |\n| `$intercepted-\u003eassertIsNotMixed();`              |\n\n| Header Assertions                                   | Parameters                           |\n|:----------------------------------------------------|:-------------------------------------|\n| `$intercepted-\u003eassertHasHeader($header);`           | `$header` string                     |\n| `$intercepted-\u003eassertMissingHeader($header);`       | `$header` string                     |\n| `$intercepted-\u003eassertHeaderIs($header, $value);`    | `$header` string\u003cbr/\u003e`$value` string |\n| `$intercepted-\u003eassertHeaderIsNot($header, $value);` | `$header` string\u003cbr/\u003e`$value` string |\n\n| Priority Assertions                           | Parameters      |\n|:----------------------------------------------|:----------------|\n| `$intercepted-\u003eassertPriority($priority);`    | `$priority` int |\n| `$intercepted-\u003eassertNotPriority($priority);` | `$priority` int |\n| `$intercepted-\u003eassertPriorityIsHighest();`    |                 |\n| `$intercepted-\u003eassertPriorityNotHighest();`   |                 |\n| `$intercepted-\u003eassertPriorityIsHigh();`       |                 |\n| `$intercepted-\u003eassertPriorityNotHigh();`      |                 |\n| `$intercepted-\u003eassertPriorityIsNormal();`     |                 |\n| `$intercepted-\u003eassertPriorityNotNormal();`    |                 |\n| `$intercepted-\u003eassertPriorityIsLow();`        |                 |\n| `$intercepted-\u003eassertPriorityNotLow();`       |                 |\n| `$intercepted-\u003eassertPriorityIsLowest();`     |                 |\n| `$intercepted-\u003eassertPriorityIsLowest();`     |                 |\n\n| Attachment Assertions                                  | Parameters         |\n|:-------------------------------------------------------|:-------------------|\n| `$intercepted-\u003eassertHasAttachment($filename);`        | `$filename` string |\n| `$intercepted-\u003eassertHasAttachments();`                |                    |\n| `$intercepted-\u003eassertMissingAttachment($filename);`    | `$filename` string |\n| `$intercepted-\u003eassertMissingAttachments();`            |                    |\n| `$intercepted-\u003eassertHasEmbeddedImage($filename);`     | `$filename` string |\n| `$intercepted-\u003eassertHasEmbeddedImages();`             |                    |\n| `$intercepted-\u003eassertMissingEmbeddedImage($filename);` | `$filename` string |\n| `$intercepted-\u003eassertMissingEmbeddedImages();`         |                    |\n\n#### Assertion Methods\n\n| Assertions                                                 | Parameters                                                   |\n|:-----------------------------------------------------------|:-------------------------------------------------------------|\n| `$this-\u003eassertMailSentTo($to, $mail);`                     | `$to` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email     |\n| `$this-\u003eassertMailNotSentTo($to, $mail);`                  | `$to` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email     |\n| `$this-\u003eassertMailSentFrom($from, $mail);`                 | `$from` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email   |\n| `$this-\u003eassertMailNotSentFrom($from, $mail);`              | `$from` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email   |\n| `$this-\u003eassertMailSubject($subject, $mail);`               | `$subject` string\u003cbr/\u003e`$mail` AssertableMessage, Email       |\n| `$this-\u003eassertMailNotSubject($subject, $mail);`            | `$subject` string\u003cbr/\u003e`$mail` AssertableMessage, Email       |\n| `$this-\u003eassertMailBodyContainsString($content, $mail);`    | `$content` string\u003cbr/\u003e`$mail` AssertableMessage, Email       |\n| `$this-\u003eassertMailBodyNotContainsString($content, $mail);` | `$content` string\u003cbr/\u003e`$mail` AssertableMessage, Email       |\n| `$this-\u003eassertMailRepliesTo($reply, $mail);`               | `$reply` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email  |\n| `$this-\u003eassertMailNotRepliesTo($reply, $mail);`            | `$reply` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email  |\n| `$this-\u003eassertMailCc($cc, $mail);`                         | `$cc` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email     |\n| `$this-\u003eassertMailNotCc($cc, $mail);`                      | `$cc` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email     |\n| `$this-\u003eassertMailBcc($cc, $mail);`                        | `$bcc` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email    |\n| `$this-\u003eassertMailNotBcc($cc, $mail);`                     | `$bcc` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email    |\n| `$this-\u003eassertMailSender($sender, $mail);`                 | `$sender` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailNotSender($sender, $mail);`              | `$sender` array, string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailReturnPath($returnPath, $mail);`         | `$returnPath` string\u003cbr/\u003e`$mail` AssertableMessage, Email    |\n| `$this-\u003eassertMailNotReturnPath($returnPath, $mail);`      | `$returnPath` string\u003cbr/\u003e`$mail` AssertableMessage, Email    |\n\n| Content Type Assertions                            | Parameters                       |\n|:---------------------------------------------------|:---------------------------------|\n| `$this-\u003eassertMailIsPlain($mail);`                 | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsNotPlain($mail);`              | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailHasPlainContent($mail);`         | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailDoesNotHavePlainContent($mail);` | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsHtml($mail);`                  | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsNotHtml($mail);`               | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailHasHtmlContent($mail);`          | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailDoesNotHaveHtmlContent($mail);`  | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsAlternative($mail);`           | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsNotAlternative($mail);`        | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsMixed($mail);`                 | `$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailIsNotMixed($mail);`              | `$mail` AssertableMessage, Email |\n\n| Header Assertions                                       | Parameters                                                                |\n|:--------------------------------------------------------|:--------------------------------------------------------------------------|\n| `$this-\u003eassertMailHasHeader($header, $mail);`           | `$header` string\u003cbr/\u003e`$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailMissingHeader($header, $mail);`       | `$header` string\u003cbr/\u003e`$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailHeaderIs($header, $value, $mail);`    | `$header` string\u003cbr/\u003e`$value` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailHeaderIsNot($header, $value, $mail);` | `$header` string\u003cbr/\u003e`$value` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n\n| Priority Assertions                               | Parameters                                           |\n|:--------------------------------------------------|:-----------------------------------------------------|\n| `$this-\u003eassertMailPriority($priority, $mail);`    | `$priority` int\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailNotPriority($priority, $mail);` | `$priority` int\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `$this-\u003eassertMailPriorityIsHighest($mail);`      | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityNotHighest($mail);`     | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityIsHigh($mail);`         | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityNotHigh($mail);`        | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityIsNormal($mail);`       | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityNotNormal($mail);`      | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityIsLow($mail);`          | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityNotLow($mail);`         | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityIsLowest($mail);`       | `$mail` AssertableMessage, Email                     |\n| `$this-\u003eassertMailPriorityIsLowest($mail);`       | `$mail` AssertableMessage, Email                     |\n\n| Attachment Assertions                              | Parameters                                              |\n|:---------------------------------------------------|:--------------------------------------------------------|\n| `this-\u003eassertMailHasAttachment($filename);`        | `$filename` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `this-\u003eassertMailHasAttachments();`                | `$mail` AssertableMessage, Email                        |\n| `this-\u003eassertMailMissingAttachment($filename);`    | `$filename` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `this-\u003eassertMailMissingAttachments();`            | `$mail` AssertableMessage, Email                        |\n| `this-\u003eassertMailHasEmbeddedImage($filename);`     | `$filename` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `this-\u003eassertMailHasEmbeddedImages();`             | `$mail` AssertableMessage, Email                        |\n| `this-\u003eassertMailMissingEmbeddedImage($filename);` | `$filename` string\u003cbr/\u003e`$mail` AssertableMessage, Email |\n| `this-\u003eassertMailMissingEmbeddedImages();`         | `$mail` AssertableMessage, Email                        |\n\nYou should use each item of the `interceptedMail()` collection as the mail object for all assertions.\n\nIf you are injecting your own headers or need access to other headers in the email, use this assertion to verify they exist and are set properly. These assertions require the header name and the compiled email.\n\n### Other assertions\n\nSince `$this-\u003einterceptedMail()` returns a collection of `AssertableMessage` objects. You are free to dissect and look into those objects using any methods available to Symfony's Email API. Head over to the [Symfony Email Docs](https://symfony.com/doc/current/mailer.html) for more detailed info.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email brandon@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.\n\n## Credits\n\n- [Brandon Ferens](https://github.com/brandonferens)\n- [Michael Fox](https://github.com/michaelfox)\n\n## Sponsorship\n\nDevelopment of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Fmail-intercept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirschbaum-development%2Fmail-intercept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Fmail-intercept/lists"}