{"id":15561181,"url":"https://github.com/thecodingmachine/utils.mailer.db-mail-service","last_synced_at":"2025-03-29T04:18:37.948Z","repository":{"id":13479732,"uuid":"16169943","full_name":"thecodingmachine/utils.mailer.db-mail-service","owner":"thecodingmachine","description":"This package contains a mailer that does not send any mail! Instead, it stores the mail to be sent in a database 'mails' table. The DB mailer can later forward the mail to a real mailer that will indeed send the mail.","archived":false,"fork":false,"pushed_at":"2018-05-23T08:55:43.000Z","size":230,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"1.0","last_synced_at":"2025-03-25T05:11:07.740Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-23T10:55:47.000Z","updated_at":"2015-11-12T11:13:00.000Z","dependencies_parsed_at":"2022-09-22T14:40:59.999Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/utils.mailer.db-mail-service","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.db-mail-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.db-mail-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.db-mail-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.db-mail-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/utils.mailer.db-mail-service/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246135799,"owners_count":20729062,"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-10-02T16:05:59.804Z","updated_at":"2025-03-29T04:18:37.926Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mouf's DBMailService\r\n====================\r\n\r\nStoring outgoing mails\r\n----------------------\r\n\r\nIn Mouf, *emails* are sent using *MailServices*.\u003cbr/\u003e\r\nThis package contains a mailer that does not send any mail! Instead, it stores the mail to\r\nbe sent in a database table. The DB mailer can also forward the mail to a real mailer that will indeed send the mail (usually a [**SmtpMailService**](http://mouf-php.com/packages/mouf/utils.mailer.smtp-mail-service/README.md))\r\n\r\nMails are stored in the `outgoing_mails` table while \"from\", \"to\", \"cc\" and \"bcc\" fields are stored in the \r\n`outgoing_mail_addresses` table.\r\nThe stored mails can later be viewed using Mouf's user interface and can also be accessed through methods of this class.\r\n\r\n![Mouf's DBMailService Outgoing Mails screenshot](doc/images/screenshot_outgoing_mails.png)\r\n\r\nThis UI is great in a development process, when you want to actually see what your application is sending \r\nwithout actually sending the mail, but is also very useful in production, in order to be able to verify\r\nwhat mails your application is sending. \r\n\r\nInstalling DBMailService\r\n------------------------\r\n\r\nThere is an install process for this package. It will create a database patch. Once you have run the install process,\r\nyou will need to install the patch.\r\n\r\nThe patch will create 2 tables if they are not alreay there: \u003cstrong\u003eoutgoing_mails\u003c/strong\u003e and \u003cstrong\u003eoutgoing_mail_addresses\u003c/strong\u003e.\r\n\r\nThe install process will also create a *dbMailService* instance that will be connected to the current\r\n*dbConnection* (if it exists) and will use the *mailService* instance to actually send the mail.\r\n\r\nUsage sample\r\n------------\r\n\r\nYou use this service as you would use any MailService.\r\n\r\n\r\nFor instance, to send a mail, you just need to write:\r\n\r\n```php\r\n$mailService = Mouf::getDBMailService();\r\n\r\n$mail = new Mail();\r\n$mail-\u003esetBodyText(\"This is my mail!\");\r\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\r\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\r\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\r\n$mail-\u003esetTitle(\"My mail\");\r\n\r\n$mailService-\u003esend($mail);\r\n```\r\n\r\nAdditional features\r\n-------------------\r\n\r\nIf you pass an instance of `DBMail` (or any class implementing `DBMailInterface`) to the `send` method\r\nof the service, you can add an additionnal category and a type to your mail.\r\nThat could be used to sort sent mails later.\r\n\r\nHere is a modified sample using `DBMail`. \r\n\r\n```php\r\n$mailService = Mouf::getDBMailService();\r\n\r\n$mail = new DBMail();\r\n$mail-\u003esetBodyText(\"This is my mail!\");\r\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\r\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\r\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\r\n$mail-\u003esetTitle(\"My mail\");\r\n\r\n// Let's set the category\r\n$mail-\u003esetCategory(\"My category\");\r\n\r\n// Let's set the type\r\n$mail-\u003esetType(\"My type\");\r\n\r\n$mailService-\u003esend($mail);\r\n```\r\n\r\nAccessing the sent mails database\r\n---------------------------------\r\n\r\nYou can access the sent mails database directly from the Mouf administration interface.\r\nYou just need to click on the **Utils** menu and click the **View outgoing mails** submenu.\r\n\r\n![Mouf's DBMailService Outgoing Mails screenshot](doc/images/screenshot_outgoing_mails.png)\r\n\r\nAs you can see in the screenshot, you can view the list of sent mails. A full-text search box will search\r\nthe whole outgoing mails.\r\n\r\nForwarding mails\r\n----------------\r\n\r\nThe `DBMailService` is very useful because it stores the mails in database.\r\nObviously, you can use it for debugging purposes. However, most of the time, you will want\r\nto store the mail in database AND send it. For this, the `DBMailService` can **forward** the\r\nmail to another mail service. You just need to edit the Mouf's instance of the service and set the\r\nforward service:\r\n\r\n![Mouf's DBMailService instance](doc/images/screenshot_forward.png)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.db-mail-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Futils.mailer.db-mail-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.db-mail-service/lists"}