Skip to content

Commit db800f9

Browse files
committed
Merge branch 'master' into development
2 parents a63ecec + 09c8a99 commit db800f9

21 files changed

+426
-71
lines changed

CHANGELOG.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## 3.0.1 - 2018-03-18
8+
### Changed
9+
- Updated README.md
10+
- Deprecated `email:retry`, please use `email:resend`
11+
12+
## 3.0.0 - 2017-12-22
13+
### Added
14+
- Support for a custom sender per e-mail.
15+
16+
### Upgrade from 2.x to 3.x
17+
18+
3.0.0 added support for a custom sender per e-mail. To update please run the following command:
19+
20+
```bash
21+
php artisan migrate
22+
```
23+
24+
## 2.0.0 - 2017-12-14
25+
### Added
26+
- Support for multiple recipients, cc and bcc addresses.
27+
- Support for mailables (*)
28+
- Support for attachments
29+
- New method `later`
30+
31+
*= Only works for Laravel versions 5.5 and up because 5.5 finally introduced a method to read the mailable body.
32+
33+
### Fixed
34+
- Bug causing failed e-mails not to be resent
35+
36+
### Upgrade from 1.x to 2.x
37+
Because 2.0.0 introduced support for attachments, the database needs to be updated. Simply run the following two commands after updating your dependencies and running composer update:
38+
39+
```bash
40+
php artisan migrate
41+
```
42+
43+
## 1.1.3 - 2017-12-07
44+
### Fixed
45+
- Created a small backwards compatibility fix for Laravel versions 5.4 and below.
46+
47+
## 1.1.2 - 2017-11-18
48+
### Fixed
49+
- Incorrect auto discovery namespace for Laravel 5.5
50+
51+
52+
## 1.1.1 - 2017-08-02
53+
### Changed
54+
- Only dispatch `before.send` event during unit tests
55+
56+
## 1.1.0 - 2017-07-01
57+
### Added
58+
- PHPUnit tests
59+
- Support for CC and BCC
60+
61+
## 1.0.0 - 2017-06-29
62+
### Added
63+
64+
- Initial release of the package

README.md

Lines changed: 100 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,29 @@
1010
## Introduction
1111

1212
This is a package that stores and queues e-mails using a database table. Easily send e-mails using a cronjob and schedule e-mails that should be sent at a specific date and time.
13-
## Installation
13+
14+
## Table Of Contents
15+
16+
- [Installation](#installation)
17+
- [Usage](#usage)
18+
- [Send an e-mail](#send-an-email)
19+
- [Specify multiple recipients](#specify-multiple-recipients)
20+
- [CC and BCC](#cc-and-bcc)
21+
- [Mailables](#using-mailables)
22+
- [Attachments](#attachments)
23+
- [Custom sender](#custom-sender)
24+
- [Scheduling](#scheduling)
25+
- [Resend failed e-mails](#resend-failed-e-mails)
26+
- [Encryption (optional)](#encryption-optional)
27+
- [Test mode (optional)](#test-mode-optional)
28+
- [E-mails to send per minute](#e-mails-to-send-per-minute)
29+
30+
### Installation
1431

1532
First, require the package using composer.
1633

1734
```bash
18-
$ composer require buildcode/laravel-database-emails
35+
composer require buildcode/laravel-database-emails
1936
```
2037

2138
If you're running Laravel 5.5 or later you may skip this step. Add the service provider to your application.
@@ -27,13 +44,13 @@ Buildcode\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
2744
Publish the configuration files.
2845

2946
```bash
30-
$ php artisan vendor:publish --provider=Buildcode\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
47+
php artisan vendor:publish --provider=Buildcode\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
3148
```
3249

3350
Create the database table required for this package.
3451

3552
```bash
36-
$ php artisan migrate
53+
php artisan migrate
3754
```
3855

3956
Now add the e-mail cronjob to your scheduler.
@@ -47,17 +64,21 @@ Now add the e-mail cronjob to your scheduler.
4764
*/
4865
protected function schedule(Schedule $schedule)
4966
{
50-
$schedule->command('email:send')->everyMinute();
67+
$schedule->command('email:send', ['--timeout' => 300])->everyMinute()->withoutOverlapping(5);
5168
}
5269
```
5370

54-
## Usage
71+
Using the above configuration, the `email:send` process will exit after 5 minutes (`--timeout`) and won't overlap if the process still runs after 5 minutes (`withoutOverlapping`)
72+
73+
### Usage
5574

56-
### Create An Email
75+
#### Send an email
5776

5877
```php
78+
use Buildcode\LaravelDatabaseEmails\Email;
79+
5980
Email::compose()
60-
->label('welcome-mail-1.0')
81+
->label('welcome')
6182
->recipient('john@doe.com')
6283
->subject('This is a test')
6384
->view('emails.welcome')
@@ -67,83 +88,118 @@ Email::compose()
6788
->send();
6889
```
6990

70-
### Specify Recipients
91+
#### Specify multiple recipients
7192

7293
```php
73-
$one = 'john@doe.com';
74-
$multiple = ['john@doe.com', 'jane@doe.com'];
94+
use Buildcode\LaravelDatabaseEmails\Email;
7595

76-
Email::compose()->recipient($one);
77-
Email::compose()->recipient($multiple);
96+
Buildcode\LaravelDatabaseEmails\Email::compose()
97+
->recipient([
98+
'john@doe.com',
99+
'jane@doe.com'
100+
]);
101+
```
78102

79-
Email::compose()->cc($one);
80-
Email::compose()->cc($multiple);
103+
#### CC and BCC
81104

82-
Email::compose()->bcc($one);
83-
Email::compose()->bcc($multiple);
105+
```php
106+
use Buildcode\LaravelDatabaseEmails\Email;
107+
108+
Email::compose()
109+
->cc('john@doe.com')
110+
->cc(['john@doe.com', 'jane@doe.com'])
111+
->bcc('john@doe.com')
112+
->bcc(['john@doe.com', 'jane@doe.com']);
84113
```
85114

86-
### Mailables
115+
#### Using mailables
87116

88117
You may also pass a mailable to the e-mail composer.
89118

90119
```php
120+
use Buildcode\LaravelDatabaseEmails\Email;
121+
122+
Email::compose()
123+
->mailable(new OrderShipped())
124+
->send();
125+
```
126+
127+
#### Attachments
128+
129+
```php
130+
use Buildcode\LaravelDatabaseEmails\Email;
131+
91132
Email::compose()
92-
->mailable(new OrderShipped())
93-
->send();
133+
->attach('/path/to/file');
94134
```
95135

96-
### Attachments
136+
Or for in-memory attachments:
97137

98138
```php
139+
use Buildcode\LaravelDatabaseEmails\Email;
140+
99141
Email::compose()
100-
->attach('/path/to/file');
142+
->attachData('<p>Your order has shipped!</p>', 'order.html');
101143
```
102144

103-
Or for in-memory attachments...
145+
#### Custom Sender
104146

105147
```php
148+
use Buildcode\LaravelDatabaseEmails\Email;
149+
106150
Email::compose()
107-
->attachData('<p>Your order has shipped!</p>', 'order.html');
151+
->from('john@doe.com', 'John Doe');
108152
```
109153

110-
### Schedule An Email
154+
#### Scheduling
111155

112-
You may schedule an e-mail by calling `later` instead of `send` at the end of the chain. You must provide a Carbon instance or a strtotime valid date.
156+
You may schedule an e-mail by calling `later` instead of `send`. You must provide a Carbon instance or a strtotime valid date.
113157

114158
```php
159+
use Buildcode\LaravelDatabaseEmails\Email;
160+
115161
Email::compose()
116-
->later('+2 hours');
162+
->later('+2 hours');
117163
```
118164

119-
### Manually Sending E-mails
165+
#### Resend failed e-mails
120166

121-
If you're not running the cronjob and wish to send the queued e-mails, you can run the `email:send` command.
167+
##### Resend all failed e-mails
122168

123169
```bash
124-
$ php artisan email:send
170+
php artisan email:resend
125171
```
126172

127-
### Failed E-mails
173+
##### Resend a specific failed e-mail
128174

129-
By default, we will attempt to send an e-mail 3 times if it fails. If it still fails the 3rd time, it will permanently be marked as failed. You can change the number of times an e-mail should be attempted to be sent using the `retry.attempts` configuration.
175+
```bash
176+
php artisan email:resend 1
177+
```
130178

131-
### Retry sending failed e-mails
179+
#### Encryption (Optional)
132180

133-
If you wish to retry sending failed e-mails, you may call the `email:retry` command. The command will grab any failed e-mail and push it onto the queue. You may also provide the id of a specific e-mail.
181+
If you wish to encrypt your e-mails, please enable the `encrypt` option in the configuration file. This is disabled by default. Encryption and decryption will be handled by Laravel's built-in encryption mechanism. Please note that by encrypting the e-mail it takes more disk space.
134182

135-
```bash
136-
$ php artisan email:retry
137-
# or...
138-
$ php artisan email:retry 1
139-
```
183+
```text
184+
Without encryption
185+
186+
7 bytes (label)
187+
16 bytes (recipient)
188+
20 bytes (subject)
189+
48 bytes (view name)
190+
116 bytes (variables)
191+
1874 bytes (e-mail content)
192+
4 bytes (attempts, sending, failed, encrypted)
193+
57 bytes (created_at, updated_at, deleted_at)
194+
... x 10.000 rows = ± 21.55 MB
140195
141-
### Encryption
196+
With encryption the table size is ± 50.58 MB.
197+
```
142198

143-
If you wish to encrypt your e-mails, please enable the `encrypt` option in the configuration file. This is disabled by default. Encryption and decryption will be handled by Laravel's built-in encryption mechanism. Please note that encrypting the e-mail body takes a lot of disk space.
199+
#### Test mode (Optional)
144200

145-
### Testing Address
201+
When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.
146202

147-
If you wish to send e-mails to a test address but don't necessarily want to use a service like mailtrap, please take a look at the `testing` configuration. This is turned off by default.
203+
#### E-mails to send per minute
148204

149-
During the creation of an e-mail, the recipient will be replaced by the test e-mail. This is useful for local development or testing on a staging server.
205+
To configure how many e-mails should be sent each command, please check the `limit` option. The default is `20` e-mails every command.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
}
2727
},
2828
"require-dev": {
29-
"illuminate/database": "^5.5",
30-
"illuminate/console": "^5.5",
31-
"illuminate/validation": "^5.5",
29+
"illuminate/database": "5.5.*",
30+
"illuminate/console": "5.5.*",
31+
"illuminate/validation": "5.5.*",
3232
"orchestra/testbench": "^3.5",
3333
"orchestra/database": "^3.5",
3434
"phpunit/phpunit": "^6.0",

config/laravel-database-emails.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,24 @@
44

55
/*
66
|--------------------------------------------------------------------------
7-
| Retry Mode
7+
| Attempts
88
|--------------------------------------------------------------------------
99
|
10-
| Here you may specify the number of attempts the cronjob should get
11-
| to send an email. If the sending fails after the number of max
12-
| tries, we will no longer attempt to send that e-mail.
10+
| Here you may specify the number of times the cronjob will try to send an e-mail.
11+
| Once the max attempt count is reached, the e-mail will be marked as failed
12+
| and will no longer be sent.
1313
|
1414
*/
1515

16-
'retry' => [
17-
18-
'attempts' => 3,
19-
20-
],
16+
'attempts' => 3,
2117

2218
/*
2319
|--------------------------------------------------------------------------
2420
| Encryption
2521
|--------------------------------------------------------------------------
2622
|
27-
| Here you may enable encryption for all e-mails. If enabled, we
28-
| will automatically encrypt all the view data, recipient and
29-
| decrypt it during the sending phase.
23+
| Here you may enable encryption for all e-mails. The e-mail will be encrypted according
24+
| your application's configuration (OpenSSL AES-256-CBC by default).
3025
|
3126
*/
3227

@@ -37,9 +32,9 @@
3732
| Test E-mail
3833
|--------------------------------------------------------------------------
3934
|
40-
| When developing the application or testing on a staging server you may
41-
| wish to send all e-mails to a specific test inbox. If enabled, all
42-
| recpient emails will be hijacked and sent to the test address.
35+
| When developing your application or testing on a staging server you may
36+
| wish to send all e-mails to a specific test inbox. Once enabled, every
37+
| newly created e-mail will be sent to the specified test address.
4338
|
4439
*/
4540

@@ -60,9 +55,9 @@
6055
| Cronjob Limit
6156
|--------------------------------------------------------------------------
6257
|
63-
| Limit the number of e-mails the cronjob may send at a time. This is useful
64-
| if you want to prevent overlapping cronjobs. Keep in mind we already
65-
| handle overlapping gracefully, however setting a limit is adviced.
58+
| Limit the number of e-mails that should be sent at a time. Please ajust this
59+
| configuration based on the number of e-mails you expect to send and
60+
| the throughput of your e-mail sending provider.
6661
|
6762
*/
6863

0 commit comments

Comments
 (0)