Skip to content

Several bugfixes #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Releases
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 3.0.3 - 2018-07-24

**Fixed**

- Transforming an `Email` object to JSON would cause the encrpyted attributes to stay encrypted. This is now fixed.

## 3.0.2 - 2018-03-22

**Changed**

- Updated README.md

**Added**

- Support for process time limit

---

## 3.0.1 - 2018-03-18

**Changed**

- Updated README.md
- Deprecated `email:retry`, please use `email:resend`

---

## 3.0.0 - 2017-12-22

**Added**

- Support for a custom sender per e-mail.

**Upgrade from 2.x to 3.x**

3.0.0 added support for a custom sender per e-mail. To update please run the following command:

```bash
php artisan migrate
```

---

## 2.0.0 - 2017-12-14

**Added**

- Support for multiple recipients, cc and bcc addresses.
- Support for mailables (*)
- Support for attachments
- New method `later`

*= Only works for Laravel versions 5.5 and up because 5.5 finally introduced a method to read the mailable body.

**Fixed**
- Bug causing failed e-mails not to be resent

**Upgrade from 1.x to 2.x**
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:

```bash
php artisan migrate
```

---

## 1.1.3 - 2017-12-07

**Fixed**

- Created a small backwards compatibility fix for Laravel versions 5.4 and below.

---

## 1.1.2 - 2017-11-18

**Fixed**

- Incorrect auto discovery namespace for Laravel 5.5

---

## 1.1.1 - 2017-08-02

**Changed**

- Only dispatch `before.send` event during unit tests

---

## 1.1.0 - 2017-07-01

**Added**

- PHPUnit tests
- Support for CC and BCC

---

## 1.0.0 - 2017-06-29

**Added**

- Initial release of the package
195 changes: 190 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,197 @@
</p>
<p align="center">
<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>
<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>
<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>
<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>
<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>
</p>

## Introduction
# Package Documentation

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

Official documentation, changelog and more [is located here](https://stackkit.github.io/laravel-database-emails/).
## Contribution

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.

We feel the package is currently feature complete, but feel free to send a pull request or help improve existing code.


# Installation

Require the package using composer.

```bash
composer require stackkit/laravel-database-emails
```

If you're running Laravel 5.5 or later you may skip this step. Add the service provider to your application.

```
Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
```

Publish the configuration files.

```bash
php artisan vendor:publish --provider=Stackkit\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
```

Create the database table required for this package.

```bash
php artisan migrate
```

Add the e-mail cronjob to your scheduler

```php
<?php

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('email:send')->everyMinute()->withoutOverlapping(5);
}
```


# Usage

### Send an email

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->label('welcome')
->recipient('john@doe.com')
->subject('This is a test')
->view('emails.welcome')
->variables([
'name' => 'John Doe',
])
->send();
```

### Specify multiple recipients

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->recipient([
'john@doe.com',
'jane@doe.com'
]);
```

### CC and BCC

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->cc('john@doe.com')
->cc(['john@doe.com', 'jane@doe.com'])
->bcc('john@doe.com')
->bcc(['john@doe.com', 'jane@doe.com']);
```

### Using mailables

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

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->mailable(new OrderShipped())
->send();
```

### Attachments

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->attach('/path/to/file');
```

Or for in-memory attachments:

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->attachData('<p>Your order has shipped!</p>', 'order.html');
```

### Custom Sender

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->from('john@doe.com', 'John Doe');
```

### Scheduling

You may schedule an e-mail by calling `later` instead of `send`. You must provide a Carbon instance or a strtotime valid date.

```php
<?php

use Stackkit\LaravelDatabaseEmails\Email;

Email::compose()
->later('+2 hours');
```

### Encryption (Optional)

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.

```text
Without encryption

7 bytes (label)
16 bytes (recipient)
20 bytes (subject)
48 bytes (view name)
116 bytes (variables)
1874 bytes (e-mail content)
4 bytes (attempts, sending, failed, encrypted)
57 bytes (created_at, updated_at, deleted_at)
... x 10.000 rows = ± 21.55 MB

With encryption the table size is ± 50.58 MB.
```

### Test mode (Optional)

When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.

### E-mails to send per minute

To configure how many e-mails should be sent each command, please check the `limit` option. The default is `20` e-mails every command.
6 changes: 1 addition & 5 deletions config/laravel-database-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@

'email' => 'test@email.com',

'enabled' => function () {
return false;
// ...or...
// return app()->environment('local', 'staging');
},
'enabled' => env('LARAVEL_DATABASE_EMAILS_TESTING_ENABLED', true),

],

Expand Down
7 changes: 6 additions & 1 deletion src/MailableReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use function call_user_func_array;
use Illuminate\Container\Container;

class MailableReader
{
Expand All @@ -14,6 +15,8 @@ class MailableReader
*/
public function read(EmailComposer $composer)
{
Container::getInstance()->call([$composer->getData('mailable'), 'build']);

$this->readRecipient($composer);

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

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

$composer->setData('body', $composer->getData('mailable')->render());
$mailable = $composer->getData('mailable');

$composer->setData('body', view($mailable->view, $mailable->buildViewData()));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private function validateRecipient(EmailComposer $composer)

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

if (count($recipients) == 0) {
throw new InvalidArgumentException('No recipient specified');
}

foreach ($recipients as $recipient) {
if (! filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('E-mail address [' . $recipient . '] is invalid');
Expand Down
26 changes: 26 additions & 0 deletions tests/ConfigCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests;

use Throwable;

class ConfigCacheTest extends TestCase
{
/** @test */
public function the_configuration_file_can_be_cached()
{
$failed = false;

try {
serialize(require __DIR__ . '/../config/laravel-database-emails.php');
} catch (Throwable $e) {
$failed = true;
}

if ($failed) {
$this->fail('Configuration file cannot be serialized');
} else {
$this->assertTrue(true);
}
}
}
Loading