{"id":18654804,"url":"https://github.com/wieni/wmmailable","last_synced_at":"2026-03-07T07:32:17.570Z","repository":{"id":56543126,"uuid":"156988877","full_name":"wieni/wmmailable","owner":"wieni","description":"A modern, plugin-based API for sending mails in Drupal 8.","archived":false,"fork":false,"pushed_at":"2025-06-03T12:11:59.000Z","size":148,"stargazers_count":0,"open_issues_count":6,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-24T02:18:19.784Z","etag":null,"topics":["drupal-8","drupal-module","drupal8-module"],"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/wieni.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-11-10T14:29:53.000Z","updated_at":"2025-06-03T12:11:23.000Z","dependencies_parsed_at":"2025-02-18T11:51:04.389Z","dependency_job_id":"34be1dd1-cc20-40a1-9667-7583e96dc7d6","html_url":"https://github.com/wieni/wmmailable","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/wieni/wmmailable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmmailable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmmailable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmmailable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmmailable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wieni","download_url":"https://codeload.github.com/wieni/wmmailable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmmailable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30209729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["drupal-8","drupal-module","drupal8-module"],"created_at":"2024-11-07T07:16:39.808Z","updated_at":"2026-03-07T07:32:17.547Z","avatar_url":"https://github.com/wieni.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"wmmailable\n======================\n\n[![Latest Stable Version](https://poser.pugx.org/wieni/wmmailable/v/stable)](https://packagist.org/packages/wieni/wmmailable)\n[![Total Downloads](https://poser.pugx.org/wieni/wmmailable/downloads)](https://packagist.org/packages/wieni/wmmailable)\n[![License](https://poser.pugx.org/wieni/wmmailable/license)](https://packagist.org/packages/wieni/wmmailable)\n\n\u003e A modern, plugin-based API for sending mails in Drupal 8. Inspired by [Laravel](https://laravel.com/docs/5.7/mail)\n\n## Why?\n- No 'modern' way to handle mails in Drupal 8: messing with `hook_mail` and `hook_theme` does not really fit in the Wieni Drupal flow with [wmmodel](https://github.com/wieni/wmmodel), [wmcontroller](https://github.com/wieni/wmcontroller), etc.\n- No clean, object-oriented API, e.g. to add CC / BCC-adresses you have to manually add headers\n- Not intuitive, logic is scattered across multiple files, tends to get messy\n\n## Installation\n\nThis package requires PHP 7.1 and Drupal 8 or higher. It can be\ninstalled using Composer:\n\n```bash\n composer require wieni/wmmailable\n```\n\n## How does it work?\n\n### Building mails\n- Mails are annotated plugins\n- Each class represents one mail\n- Dependency injection is possible by implementing the `ContainerFactoryPluginInterface` ([tutorial](https://chromatichq.com/blog/dependency-injection-drupal-8-plugins))\n\n```php\n\u003c?php\n\nnamespace Drupal\\wmcustom\\Mail;\n\n/**\n * @Mailable(\n *     id = \"contact_form_submission\",\n*      template = \"mail.contact-submission\"\n * )\n */\nclass ContactFormSubmission extends MailableBase\n{\n    public function build(array $parameters): MailableInterface;\n}\n```\n\n- It is possible to take over other module's mails at the time of sending. To do this, change the `id` and `module` properties. The original mail parameters will be passed to the `build` method. Example:\n```php\n\u003c?php\n\nnamespace Drupal\\wmcustom\\Mail;\n\n/**\n * @Mailable(\n *     id = \"register_no_approval_required\",\n *     module = \"user\",\n *     template = \"mail.account-confirmation\"\n * )\n */\nclass AccountConfirmationMail extends MailableBase\n{\n    public function build(array $parameters): MailableInterface\n    {\n        $parameters['oneTimeLoginUrl'] = user_pass_reset_url($parameters['account']);\n        \n        {...}\n    }\n}\n```\n\n### Theming mails\n- Mail templates should be stored in a theme. This theme can be set in the \n `theme` value of the `wmmailable.settings` config, with the default theme \n as a fallback.\n\n- The location of the template within the theme is also configurable:\n    - the default location is in the `mail` subfolder, with the id with \n     dashes instead of underscores as template name.\n    - a custom location can be set in the annotation, in the form of a \n     path relative to the theme, with filename but without extension. \n     Dots can be used as directory seperator.\n\n- The mail formatter determines how mails are rendered. Thanks to the \n [mailsystem](https://www.drupal.org/project/mailsystem) module, we can \n change the mail formatter separately from the mail sender. This module \n provides 3 formatters. The formatters as listed here are incremental: \n they all contain the features listed in the previous formatters.\n    - _Mailable - Plain_: the most basic mail formatter. Depending on the \n     passed `Content-Type` header, this formatter will output HTML or plain \n     text mails.\n    - _Mailable - With inline styles_: allows you to attach \n     [asset libraries](https://www.drupal.org/node/2274843) to mails by \n     passing them to `MailableInterface::addLibrary` or an array of asset \n     libraries to `MailableInterface::setLibraries`.\n    - _Mailable - Foundation for Emails_: allows you to compose mails using \n     the [Inky](https://get.foundation/emails.html) templating language. \n     To use this formatter, you need to have the \n     [`thampe/inky`](https://github.com/thampe/inky) package installed. \n\n### Sending mails\n- Mails are sent through the `Mailer` service\n- Two standard `Mailer` implementations are provided: `mailable.mailer.direct` and `mailable.mailer.queued`\n- The active implementation can be changed in the `mailable.settings.yml` config\n\n```php\n\u003c?php\n\nnamespace Drupal\\wmcustom\\Form;\n\nuse Drupal\\wmmailable\\Mailer\\MailerInterface;\n\nclass ContactForm extends FormBase\n{\n    /** @var MailerInterface */\n    protected $mailer;\n\n    public function __construct(\n        MailerInterface $mailer\n    ) {\n        $this-\u003emailer = $mailer;\n    }\n\n    public function submitForm(array \u0026$form, FormStateInterface $formState)\n    {\n        $mail = $this-\u003emailer-\u003ecreate('contact_form_submission')\n            -\u003esetRecepients(['Wieni \u003cinfo@wieni.be\u003e', 'dieter@wieni.be'])\n            -\u003eaddBcc('sophie@wieni.be')\n            -\u003esetParameters(\n                compact('domain', 'firstName', 'lastName', 'email', 'question')\n            );\n        \n        $this-\u003emailer-\u003esend($mail);\n\t}\n\n\tpublic static function create(ContainerInterface $container)\n\t{\n\t    return new static(\n\t        $container-\u003eget('mailable.mailer')\n        );\n    }\n}\n```\n\n### Logging sent mails\n- When enabled, this wil log all outgoing mails - also those that aren't composed through this module.\n- To enable, configure the [mailsystem](https://www.drupal.org/project/mailsystem) module to use _Mailable - Logger_ as \n the mail sender.\n- To view logged mails, go to `/admin/reports/sent-mails` or follow the menu link at _Reports_ \u003e _Sent mails_.\n\n### Hooks and events\n- Two hooks are provided, `hook_mailable_alter` and `hook_mailable_{module}_{key}_alter`. These hooks are called after the `send` method is called on the mailable, but before the mail is sent.\n\n```php\n\u003c?php\n\nfunction wmcustom_mailable_alter(MailableInterface $mail)\n{\n    $mail-\u003esetHeader('X-SES-SOURCE-ARN', '\u003c...\u003e');\n}\n```\n\n- Two events are provided, equivalent to the hooks:\n\n```php\n\u003c?php\n\nuse Drupal\\wmmailable\\Event\\MailableAlterEvent;\nuse Drupal\\wmmailable\\WmmailableEvents;\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n\nclass MailableAlterSubscriber implements EventSubscriberInterface\n{\n    public static function getSubscribedEvents()\n    {\n        $events[WmmailableEvents::MAILABLE_ALTER][] = 'onMailAlter';\n\n        return $events;\n    }\n\n    public function onMailAlter(MailableAlterEvent $event)\n    {\n        $mailable = $event-\u003egetMailable();\n        $mailable-\u003esetSubject(\"Here's a better subject.\");\n    }\n}\n```\n\n## Changelog\nAll notable changes to this project will be documented in the\n[CHANGELOG](CHANGELOG.md) file.\n\n## Security\nIf you discover any security-related issues, please email\n[security@wieni.be](mailto:security@wieni.be) instead of using the issue\ntracker.\n\n## License\nDistributed under the MIT License. See the [LICENSE](LICENSE) file\nfor more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmmailable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwieni%2Fwmmailable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmmailable/lists"}