Skip to content

Commit 30e788f

Browse files
committed
Initial commit
0 parents  commit 30e788f

38 files changed

+3915
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/vendor
2+
/.idea
3+
vendor/
4+
composer.phar
5+
composer.lock
6+
.DS_Store
7+
.vscode
8+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Laravel Elastic Email #
2+
3+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=6CYVR8U4VDMAA)
4+
5+
A Laravel wrapper for sending emails via Elastic Email service and API capabilities that allows you to check the status of every email sent.
6+
It provides a basic email log table to store all outbound emails where you can link to a model.
7+
8+
## Installation
9+
10+
Add Laravel Elastic Email as a dependency using the composer CLI:
11+
12+
```bash
13+
composer require seinoxygen/laravel-elastic-email
14+
```
15+
16+
## Mail Service Usage
17+
18+
This package works exactly like Laravel's native mailers. Refer to Laravel's Mail documentation.
19+
20+
Add the following to your config/services.php and add the correct values to your .env file
21+
22+
```php
23+
'elastic_email' => [
24+
'key' => env('ELASTIC_KEY'),
25+
'account' => env('ELASTIC_ACCOUNT')
26+
]
27+
```
28+
29+
Add the following to your config/mail.php
30+
31+
```php
32+
'elastic_email' => [
33+
'transport' => 'elasticemail'
34+
]
35+
```
36+
37+
Next, in config/app.php, comment out Laravel's default MailServiceProvider. If using < Laravel 5.5, add the MailServiceProvider and ApiServiceProvider to the providers array
38+
39+
```php
40+
'providers' => [
41+
...
42+
SeinOxygen\ElasticEmail\MailServiceProvider::class,
43+
SeinOxygen\ElasticEmail\ApiServiceProvider::class,
44+
...
45+
],
46+
```
47+
48+
Next, in config/app.php, add the ElasticEmail to the aliases array
49+
50+
```php
51+
'aliases' => [
52+
...
53+
'ElasticEmail' => SeinOxygen\ElasticEmail\Facades\ElasticEmail::class,
54+
...
55+
],
56+
```
57+
58+
Finally switch your default mail provider to elastic email in your .env file by setting **MAIL_DRIVER=elastic_email**
59+
60+
## Outbound Email Tracking
61+
62+
To keep track of all emails sent by the driver you'll need to publish the migrations and the configuration files:
63+
64+
```bash
65+
php artisan vendor:publish --provider="SeinOxygen\ElasticEmail\ApiServiceProvider" --tag="migrations"
66+
```
67+
68+
```bash
69+
php artisan migrate
70+
```
71+
72+
```bash
73+
php artisan vendor:publish --provider="SeinOxygen\ElasticEmail\ApiServiceProvider" --tag="config"
74+
```
75+
76+
By default all outgoing emails will be stored with the Elastic Email **message_id** and **transaction_id**.
77+
78+
Check **config/elasticemail.php** for more options.
79+
80+
### Linking Outgoing Emails To Your Models ###
81+
82+
In your mailable be sure to set the with array the following way.
83+
84+
```php
85+
public function build()
86+
{
87+
// You can set ad many models you want to relate with the outgoing email
88+
$models = [
89+
[$yourmodel->id, get_class($yourmodel)],
90+
];
91+
92+
return $this
93+
->subject("My Subject")
94+
->view('my-view')
95+
->with([
96+
'models' => $models
97+
]);
98+
}
99+
```
100+
101+
Sorry if it looks ugly. I haven't found a better way to do this...yet.
102+
103+
### Capturing Webhook Events ###
104+
105+
You will need to set a webhook in Elastic Email service pointing to **yourappurl.com/webhook/elasticemail**
106+
107+
There is an event being fired when data is sent to the webhook url.
108+
109+
```php
110+
<?php
111+
112+
namespace app\Listeners;
113+
114+
use SeinOxygen\ElasticEmail\Events\WebhookCallReceived;
115+
116+
class WebhookCallListerner
117+
{
118+
public function handle(WebhookCallReceived $event)
119+
{
120+
$request = $event->request;
121+
}
122+
}
123+
```
124+
125+
## Api Usage
126+
127+
For documentation visit https://api.elasticemail.com/public/help
128+
129+
```php
130+
131+
//For contact
132+
ElasticEmail::Contact()
133+
134+
//For emails
135+
ElasticEmail::Email()
136+
137+
```
138+
139+
## Credits
140+
141+
This package is based on [ZanySoft](https://github.com/zanysoft/laravel-elastic-email)
142+
143+
## License
144+
145+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "seinoxygen/laravel-elastic-email",
3+
"description": "A Laravel wrapper for Elastic Email",
4+
"keywords": [
5+
"laravel",
6+
"email",
7+
"elastic email"
8+
],
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"company": "",
13+
"email": "seinoxygen@hotmail.com",
14+
"url": ""
15+
}
16+
],
17+
"support": {
18+
"email": "seinoxygen@hotmail.com"
19+
},
20+
"require": {
21+
"php": "^7.1|^8.0",
22+
"laravel/framework": "^6.0|^7.0|^8.0|^9.0",
23+
"guzzlehttp/guzzle": "^6.3|^7.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"SeinOxygen\\ElasticEmail\\": "src/"
28+
}
29+
},
30+
"extra": {
31+
"laravel": {
32+
"providers": [
33+
"SeinOxygen\\ElasticEmail\\MailServiceProvider"
34+
],
35+
"aliases": {
36+
"ElasticEmail": "SeinOxygen\\ElasticEmail\\Facades\\ElasticEmail"
37+
}
38+
}
39+
},
40+
"minimum-stability": "stable"
41+
}

config/elasticemail.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Elastic Email API Key
7+
|--------------------------------------------------------------------------
8+
|
9+
| This value is the API key provided by Elastic Email.
10+
|
11+
*/
12+
'key' => env('ELASTIC_KEY'),
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Elastic Email Account Email
17+
|--------------------------------------------------------------------------
18+
|
19+
| This value is the account email provided by Elastic Email.
20+
|
21+
*/
22+
'account' => env('ELASTIC_ACCOUNT'),
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Elastic Email Webhook Secret
27+
|--------------------------------------------------------------------------
28+
|
29+
| This value is the webhook secret provided by Elastic Email.
30+
|
31+
*/
32+
'webhook_secret' => env('ELASTIC_WEBHOOK_SECRET'),
33+
34+
/*
35+
|--------------------------------------------------------------------------
36+
| Save Webhook Hits
37+
|--------------------------------------------------------------------------
38+
|
39+
| Keep track of all webhooks received from Elastic Email in the elatic_email_hits table.
40+
|
41+
*/
42+
'save_hits' => false,
43+
44+
/*
45+
|--------------------------------------------------------------------------
46+
| Save Webhook Hits For 30 Days
47+
|--------------------------------------------------------------------------
48+
|
49+
| This will delete all records older than 30 days.
50+
| Use null to disable this funtionality.
51+
|
52+
*/
53+
'delete_after_days' => null,
54+
55+
];
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateElasticEmailHitsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('elastic_email_hits', function (Blueprint $table) {
17+
$table->id();
18+
$table->uuid('transaction_id')->index();
19+
$table->string('message_id')->index();
20+
$table->string('status');
21+
$table->json('data');
22+
$table->timestamps();
23+
});
24+
25+
Schema::create('elastic_email_outbound', function (Blueprint $table) {
26+
$table->id();
27+
$table->string('message_id')->unique();
28+
$table->uuid('transaction_id')->unique();
29+
$table->string('from');
30+
$table->string('to');
31+
$table->string('cc')->nullable();
32+
$table->string('subject');
33+
$table->longText('body');
34+
$table->string('attachments')->nullable();
35+
$table->integer('created_by')->nullable();
36+
$table->timestamp('delivered_at')->nullable();
37+
$table->timestamp('opened_at')->nullable();
38+
$table->timestamps();
39+
});
40+
41+
Schema::create('model_has_elastic_email_outbound', function (Blueprint $table) {
42+
$table->id();
43+
$table->integer('elastic_email_outbound_id')->index();
44+
$table->integer('model_id')->index();
45+
$table->string('model_type')->index();
46+
$table->timestamps();
47+
});
48+
}
49+
50+
/**
51+
* Reverse the migrations.
52+
*
53+
* @return void
54+
*/
55+
public function down()
56+
{
57+
Schema::dropIfExists('elastic_email_hits');
58+
Schema::dropIfExists('elastic_email_outbound');
59+
Schema::dropIfExists('model_has_elastic_email_outbound');
60+
}
61+
}

routes/web.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
use Illuminate\Support\Facades\Route;
3+
use SeinOxygen\ElasticEmail\Http\Controllers\WebhookController;
4+
5+
Route::get('/webhook/elasticemail', [WebhookController::class, 'store']);

0 commit comments

Comments
 (0)