{"id":33999904,"url":"https://github.com/stackkit/laravel-database-emails","last_synced_at":"2025-12-13T09:08:45.363Z","repository":{"id":22245245,"uuid":"95295924","full_name":"stackkit/laravel-database-emails","owner":"stackkit","description":"Store e-mails in the database and send them using a cronjob","archived":false,"fork":false,"pushed_at":"2025-03-16T16:15:17.000Z","size":294,"stargazers_count":38,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-22T14:22:39.296Z","etag":null,"topics":["email","laravel","laravel-package","queue"],"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/stackkit.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}},"created_at":"2017-06-24T12:21:40.000Z","updated_at":"2025-03-16T16:12:56.000Z","dependencies_parsed_at":"2024-04-25T20:30:32.035Z","dependency_job_id":null,"html_url":"https://github.com/stackkit/laravel-database-emails","commit_stats":{"total_commits":123,"total_committers":6,"mean_commits":20.5,"dds":0.08943089430894313,"last_synced_commit":"ef36731504d610361efac84ad7bf77ea42ccfc4f"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/stackkit/laravel-database-emails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackkit%2Flaravel-database-emails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackkit%2Flaravel-database-emails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackkit%2Flaravel-database-emails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackkit%2Flaravel-database-emails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackkit","download_url":"https://codeload.github.com/stackkit/laravel-database-emails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackkit%2Flaravel-database-emails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702903,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["email","laravel","laravel-package","queue"],"created_at":"2025-12-13T09:08:44.712Z","updated_at":"2025-12-13T09:08:45.353Z","avatar_url":"https://github.com/stackkit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Run tests](https://github.com/stackkit/laravel-database-emails/actions/workflows/run-tests.yml/badge.svg)](https://github.com/stackkit/laravel-database-emails/actions/workflows/run-tests.yml)\n[![Latest Version on Packagist](https://poser.pugx.org/stackkit/laravel-database-emails/v/stable.svg)](https://packagist.org/packages/stackkit/laravel-database-emails)\n[![Total Downloads](https://poser.pugx.org/stackkit/laravel-database-emails/downloads.svg)](https://packagist.org/packages/stackkit/laravel-database-emails)\n\n# Introduction\n\nThis package allows you to store and send e-mails using the database. \n\n# Requirements\n\nThis package requires Laravel 11 or 12.\n\n# Installation\n\nRequire the package using composer.\n\n```shell\ncomposer require stackkit/laravel-database-emails\n```\n\nPublish the configuration files.\n\n```shell\nphp artisan vendor:publish --tag=database-emails-config\nphp artisan vendor:publish --tag=database-emails-migrations\n```\n\nCreate the database table required for this package.\n\n```shell\nphp artisan migrate\n```\n\nAdd the e-mail cronjob to your scheduler\n\n```php\nprotected function schedule(Schedule $schedule)\n{\n     $schedule-\u003ecommand('email:send')-\u003eeveryMinute()-\u003ewithoutOverlapping(5);\n}\n```\n\n\n# Usage\n\n### Send an email\n\nE-mails are composed the same way mailables are created.\n\n```php\nuse Stackkit\\LaravelDatabaseEmails\\Email;\nuse Illuminate\\Mail\\Mailables\\Content;\nuse Stackkit\\LaravelDatabaseEmails\\Attachment;\nuse Illuminate\\Mail\\Mailables\\Envelope;\n\nEmail::compose()\n    -\u003econtent(fn (Content $content) =\u003e $content\n        -\u003eview('tests::dummy')\n        -\u003ewith(['name' =\u003e 'John Doe'])\n    )\n    -\u003eenvelope(fn (Envelope $envelope) =\u003e $envelope\n        -\u003esubject('Hello')\n        -\u003efrom('johndoe@example.com', 'John Doe')\n        -\u003eto('janedoe@example.com', 'Jane Doe')\n    )\n    -\u003eattachments([\n        Attachment::fromStorageDisk('s3', '/invoices/john-doe/march-2024.pdf'),\n    ])\n    -\u003esend();\n])\n```\n\n### Sending emails to users in your application\n\n```php\nEmail::compose()\n    -\u003euser($user)\n    -\u003esend();\n```\n\nBy default, the `name` column will be used to set the recipient's name. If you wish to use something different, you should implement the `preferredEmailName` method in your model.\n\n```php\nclass User extends Model\n{\n    public function preferredEmailName(): string\n    {\n        return $this-\u003efirst_name;\n    }\n}\n```\n\nBy default, the `email` column will be used to set the recipient's e-mail address. If you wish to use something different, you should implement the `preferredEmailAddress` method in your model.\n\n```php\nclass User extends Model\n{\n    public function preferredEmailAddress(): string\n    {\n        return $this-\u003ework_email;\n    }\n}\n```\n\nBy default, the app locale will be used. If you wish to use something different, you should implement the `preferredEmailLocale` method in your model.\n\n```php\nclass User extends Model implements HasLocalePreference\n{\n    public function preferredLocale(): string\n    {\n        return $this-\u003elocale;\n    }\n}\n```\n\n### Using mailables\n\nYou may also pass a mailable to the e-mail composer.\n\n```php\nEmail::compose()\n    -\u003emailable(new OrderShipped())\n    -\u003esend();\n```\n\n### Attachments\n\nTo start attaching files to your e-mails, you may use the `attachments` method like you normally would in Laravel.\nHowever, you will have to use this package's `Attachment` class.\n\n\n```php\nuse Stackkit\\LaravelDatabaseEmails\\Attachment;\n\nEmail::compose()\n    -\u003eattachments([\n        Attachment::fromPath(__DIR__.'/files/pdf-sample.pdf'),\n        Attachment::fromPath(__DIR__.'/files/my-file.txt')-\u003eas('Test123 file'),\n        Attachment::fromStorageDisk('my-custom-disk', 'test.txt'),\n    ])\n    -\u003esend();\n```\n\n\u003e [!NOTE]\n\u003e `Attachment::fromData()` and `Attachment::fromStorage()` are not supported as they work with raw data.\n\n### Attaching models to e-mails\n\nYou may attach a model to an e-mail. This can be useful to attach a user or another model that belongs to the e-mail.\n\n```php\nEmail::compose()\n    -\u003emodel(User::find(1));\n```\n\n### Scheduling\n\nYou may schedule an e-mail by calling `later` instead of `send`. You must provide a Carbon instance or a strtotime valid date.\n\n```php\nEmail::compose()\n    -\u003elater('+2 hours');\n```\n\n### Queueing e-mails\n\n\u003e [!IMPORTANT]\n\u003e When queueing mail using the `queue` function, it is no longer necessary to schedule the `email:send` command.\n\n```php\nEmail::compose()-\u003equeue();\n\n// On a specific connection\nEmail::compose()-\u003equeue(connection: 'sqs');\n\n// On a specific queue\nEmail::compose()-\u003equeue(queue: 'email-queue');\n\n// Delay (send mail in 10 minutes)\nEmail::compose()-\u003equeue(delay: now()-\u003eaddMinutes(10));\n```\n\nIf you need more flexibility, you may also pass your own job class:\n\n```php\nEmail::compose()-\u003equeue(jobClass: CustomSendEmailJob::class);\n```\n\nIt could look like this:\n\n```php\n\u003c?php\n\nnamespace App\\Jobs;\n\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Stackkit\\LaravelDatabaseEmails\\SendEmailJob;\n\nclass CustomSendEmailJob extends SendEmailJob implements ShouldQueue\n{\n    // Define custom retries, backoff, etc...\n}\n```\n\n### Test mode\n\nWhen enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.\n\n```dotenv\nDB_EMAILS_TESTING_ENABLED=true\nDB_EMAILS_TESTING_EMAIL=your-test-recipient@example.com\n```\n\n### E-mails to send per minute\n\nTo configure how many e-mails should be sent each command.\n\n```dotenv\nDB_EMAILS_LIMIT=20\n```\n\n### Send e-mails immediately\n\nUseful during development when Laravel Scheduler is not running\n\nTo enable, set the following environment variable:\n\n```dotenv\nDB_EMAILS_IMMEDIATELY=true\n```\n\n### Pruning models\n\n```php\nuse Stackkit\\LaravelDatabaseEmails\\Email;\n\n$schedule-\u003ecommand('model:prune', [\n    '--model' =\u003e [Email::class],\n])-\u003edaily();\n```\n\nBy default, e-mails are pruned when they are older than 6 months.\n\nYou may change that by adding the following to the AppServiceProvider.php:\n\n```php\nuse Stackkit\\LaravelDatabaseEmails\\Email;\n\npublic function register(): void\n{\n    Email::pruneWhen(function (Email $email) {\n        return $email-\u003ewhere(...);\n    });\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackkit%2Flaravel-database-emails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackkit%2Flaravel-database-emails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackkit%2Flaravel-database-emails/lists"}