Skip to content

Commit 4cd8c1f

Browse files
Merge pull request #16 from stackkit/development
Several bugfixes
2 parents 8cf7923 + f1ad986 commit 4cd8c1f

8 files changed

+358
-27
lines changed

CHANGELOG.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Releases
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.3 - 2018-07-24
8+
9+
**Fixed**
10+
11+
- Transforming an `Email` object to JSON would cause the encrpyted attributes to stay encrypted. This is now fixed.
12+
13+
## 3.0.2 - 2018-03-22
14+
15+
**Changed**
16+
17+
- Updated README.md
18+
19+
**Added**
20+
21+
- Support for process time limit
22+
23+
---
24+
25+
## 3.0.1 - 2018-03-18
26+
27+
**Changed**
28+
29+
- Updated README.md
30+
- Deprecated `email:retry`, please use `email:resend`
31+
32+
---
33+
34+
## 3.0.0 - 2017-12-22
35+
36+
**Added**
37+
38+
- Support for a custom sender per e-mail.
39+
40+
**Upgrade from 2.x to 3.x**
41+
42+
3.0.0 added support for a custom sender per e-mail. To update please run the following command:
43+
44+
```bash
45+
php artisan migrate
46+
```
47+
48+
---
49+
50+
## 2.0.0 - 2017-12-14
51+
52+
**Added**
53+
54+
- Support for multiple recipients, cc and bcc addresses.
55+
- Support for mailables (*)
56+
- Support for attachments
57+
- New method `later`
58+
59+
*= Only works for Laravel versions 5.5 and up because 5.5 finally introduced a method to read the mailable body.
60+
61+
**Fixed**
62+
- Bug causing failed e-mails not to be resent
63+
64+
**Upgrade from 1.x to 2.x**
65+
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:
66+
67+
```bash
68+
php artisan migrate
69+
```
70+
71+
---
72+
73+
## 1.1.3 - 2017-12-07
74+
75+
**Fixed**
76+
77+
- Created a small backwards compatibility fix for Laravel versions 5.4 and below.
78+
79+
---
80+
81+
## 1.1.2 - 2017-11-18
82+
83+
**Fixed**
84+
85+
- Incorrect auto discovery namespace for Laravel 5.5
86+
87+
---
88+
89+
## 1.1.1 - 2017-08-02
90+
91+
**Changed**
92+
93+
- Only dispatch `before.send` event during unit tests
94+
95+
---
96+
97+
## 1.1.0 - 2017-07-01
98+
99+
**Added**
100+
101+
- PHPUnit tests
102+
- Support for CC and BCC
103+
104+
---
105+
106+
## 1.0.0 - 2017-06-29
107+
108+
**Added**
109+
110+
- Initial release of the package

README.md

+190-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,197 @@
33
</p>
44
<p align="center">
55
<a href="https://travis-ci.org/stackkit/laravel-database-emails"><img src="https://travis-ci.org/stackkit/laravel-database-emails.svg?branch=master" alt="Build Status"></a>
6-
<a href="https://packagist.org/packages/buildcode/laravel-database-emails"><img src="https://poser.pugx.org/buildcode/laravel-database-emails/v/stable.svg" alt="Latest Stable Version"></a>
7-
<a href="https://packagist.org/packages/buildcode/laravel-database-emails"><img src="https://poser.pugx.org/buildcode/laravel-database-emails/license.svg" alt="License"></a>
6+
<a href="https://packagist.org/packages/stackkit/laravel-database-emails"><img src="https://poser.pugx.org/stackkit/laravel-database-emails/v/stable.svg" alt="Latest Stable Version"></a>
7+
<a href="https://packagist.org/packages/stackkit/laravel-database-emails"><img src="https://poser.pugx.org/stackkit/laravel-database-emails/license.svg" alt="License"></a>
88
</p>
99

10-
## Introduction
10+
# Package Documentation
1111

12-
This package allows you to easily send e-mails using a database table.
12+
This package allows you to store and send e-mails using a database.
1313

14-
Official documentation, changelog and more [is located here](https://stackkit.github.io/laravel-database-emails/).
14+
## Contribution
15+
16+
The package is MIT licenced, meaning it's open source and you are free to copy or fork it and modify it any way you wish.
17+
18+
We feel the package is currently feature complete, but feel free to send a pull request or help improve existing code.
19+
20+
21+
# Installation
22+
23+
Require the package using composer.
24+
25+
```bash
26+
composer require stackkit/laravel-database-emails
27+
```
28+
29+
If you're running Laravel 5.5 or later you may skip this step. Add the service provider to your application.
30+
31+
```
32+
Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
33+
```
34+
35+
Publish the configuration files.
36+
37+
```bash
38+
php artisan vendor:publish --provider=Stackkit\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
39+
```
40+
41+
Create the database table required for this package.
42+
43+
```bash
44+
php artisan migrate
45+
```
46+
47+
Add the e-mail cronjob to your scheduler
48+
49+
```php
50+
<?php
51+
52+
/**
53+
* Define the application's command schedule.
54+
*
55+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
56+
* @return void
57+
*/
58+
protected function schedule(Schedule $schedule)
59+
{
60+
$schedule->command('email:send')->everyMinute()->withoutOverlapping(5);
61+
}
62+
```
63+
64+
65+
# Usage
66+
67+
### Send an email
68+
69+
```php
70+
<?php
71+
72+
use Stackkit\LaravelDatabaseEmails\Email;
73+
74+
Email::compose()
75+
->label('welcome')
76+
->recipient('[email protected]')
77+
->subject('This is a test')
78+
->view('emails.welcome')
79+
->variables([
80+
'name' => 'John Doe',
81+
])
82+
->send();
83+
```
84+
85+
### Specify multiple recipients
86+
87+
```php
88+
<?php
89+
90+
use Stackkit\LaravelDatabaseEmails\Email;
91+
92+
Email::compose()
93+
->recipient([
94+
95+
96+
]);
97+
```
98+
99+
### CC and BCC
100+
101+
```php
102+
<?php
103+
104+
use Stackkit\LaravelDatabaseEmails\Email;
105+
106+
Email::compose()
107+
108+
109+
110+
111+
```
112+
113+
### Using mailables
114+
115+
You may also pass a mailable to the e-mail composer.
116+
117+
```php
118+
<?php
119+
120+
use Stackkit\LaravelDatabaseEmails\Email;
121+
122+
Email::compose()
123+
->mailable(new OrderShipped())
124+
->send();
125+
```
126+
127+
### Attachments
128+
129+
```php
130+
<?php
131+
132+
use Stackkit\LaravelDatabaseEmails\Email;
133+
134+
Email::compose()
135+
->attach('/path/to/file');
136+
```
137+
138+
Or for in-memory attachments:
139+
140+
```php
141+
<?php
142+
143+
use Stackkit\LaravelDatabaseEmails\Email;
144+
145+
Email::compose()
146+
->attachData('<p>Your order has shipped!</p>', 'order.html');
147+
```
148+
149+
### Custom Sender
150+
151+
```php
152+
<?php
153+
154+
use Stackkit\LaravelDatabaseEmails\Email;
155+
156+
Email::compose()
157+
->from('[email protected]', 'John Doe');
158+
```
159+
160+
### Scheduling
161+
162+
You may schedule an e-mail by calling `later` instead of `send`. You must provide a Carbon instance or a strtotime valid date.
163+
164+
```php
165+
<?php
166+
167+
use Stackkit\LaravelDatabaseEmails\Email;
168+
169+
Email::compose()
170+
->later('+2 hours');
171+
```
172+
173+
### Encryption (Optional)
174+
175+
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.
176+
177+
```text
178+
Without encryption
179+
180+
7 bytes (label)
181+
16 bytes (recipient)
182+
20 bytes (subject)
183+
48 bytes (view name)
184+
116 bytes (variables)
185+
1874 bytes (e-mail content)
186+
4 bytes (attempts, sending, failed, encrypted)
187+
57 bytes (created_at, updated_at, deleted_at)
188+
... x 10.000 rows = ± 21.55 MB
189+
190+
With encryption the table size is ± 50.58 MB.
191+
```
192+
193+
### Test mode (Optional)
194+
195+
When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.
196+
197+
### E-mails to send per minute
198+
199+
To configure how many e-mails should be sent each command, please check the `limit` option. The default is `20` e-mails every command.

config/laravel-database-emails.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@
4242

4343
'email' => '[email protected]',
4444

45-
'enabled' => function () {
46-
return false;
47-
// ...or...
48-
// return app()->environment('local', 'staging');
49-
},
45+
'enabled' => env('LARAVEL_DATABASE_EMAILS_TESTING_ENABLED', true),
5046

5147
],
5248

src/MailableReader.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use function call_user_func_array;
7+
use Illuminate\Container\Container;
78

89
class MailableReader
910
{
@@ -14,6 +15,8 @@ class MailableReader
1415
*/
1516
public function read(EmailComposer $composer)
1617
{
18+
Container::getInstance()->call([$composer->getData('mailable'), 'build']);
19+
1720
$this->readRecipient($composer);
1821

1922
$this->readFrom($composer);
@@ -123,7 +126,9 @@ private function readBody(EmailComposer $composer)
123126

124127
$composer->setData('view', '');
125128

126-
$composer->setData('body', $composer->getData('mailable')->render());
129+
$mailable = $composer->getData('mailable');
130+
131+
$composer->setData('body', view($mailable->view, $mailable->buildViewData()));
127132
}
128133

129134
/**

src/Validator.php

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ private function validateRecipient(EmailComposer $composer)
6767

6868
$recipients = (array) $composer->getData('recipient');
6969

70+
if (count($recipients) == 0) {
71+
throw new InvalidArgumentException('No recipient specified');
72+
}
73+
7074
foreach ($recipients as $recipient) {
7175
if (! filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
7276
throw new InvalidArgumentException('E-mail address [' . $recipient . '] is invalid');

tests/ConfigCacheTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Throwable;
6+
7+
class ConfigCacheTest extends TestCase
8+
{
9+
/** @test */
10+
public function the_configuration_file_can_be_cached()
11+
{
12+
$failed = false;
13+
14+
try {
15+
serialize(require __DIR__ . '/../config/laravel-database-emails.php');
16+
} catch (Throwable $e) {
17+
$failed = true;
18+
}
19+
20+
if ($failed) {
21+
$this->fail('Configuration file cannot be serialized');
22+
} else {
23+
$this->assertTrue(true);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)