Updated Mailer (#113)
Removed email settings from settings.json and moved them to the .env file to use Laravel's mailer functionality. references to the old mailer has been removed from settings.json, data sorting class and the settings template file the front end script has also been updated to accomodate different message types, starting with a test message so members can make sure the settings defined in the .env are working
This commit is contained in:
parent
9923f087a6
commit
b37e64d062
11 changed files with 134 additions and 82 deletions
35
app/Http/Controllers/API/MailAPIController.php
Normal file
35
app/Http/Controllers/API/MailAPIController.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\API;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use App\Mail\SystemEmail;
|
||||||
|
|
||||||
|
class MailAPIController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//init stuff
|
||||||
|
public function sendNotify(Request $request)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
try {
|
||||||
|
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($request->content));
|
||||||
|
$result = [
|
||||||
|
'type' => 'mail_good',
|
||||||
|
'message' => 'Mail Sent',
|
||||||
|
];
|
||||||
|
} catch (ERROR $e) {
|
||||||
|
$result = [
|
||||||
|
'type' => 'mail_not_good',
|
||||||
|
'message' => 'Mail Not Sent',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
}
|
17
app/Http/Controllers/SystemMailController.php
Normal file
17
app/Http/Controllers/SystemMailController.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SystemMailController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Send notification
|
||||||
|
*/
|
||||||
|
public function sendNotification()
|
||||||
|
{
|
||||||
|
$message = "This is something important. Probably";
|
||||||
|
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($message));
|
||||||
|
}
|
||||||
|
}
|
55
app/Mail/SystemEmail.php
Normal file
55
app/Mail/SystemEmail.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Mail\Mailables\Address;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class SystemEmail extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*/
|
||||||
|
public function __construct(public $notifyText)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*/
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
from: new Address(env('MAIL_USERNAME'), 'System Notification'),
|
||||||
|
subject: 'Notification',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'mail.notify',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||||
|
*/
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -265,7 +265,6 @@ class SortingService
|
||||||
public function settings()
|
public function settings()
|
||||||
{
|
{
|
||||||
$global = $this->settings->getGlobal();
|
$global = $this->settings->getGlobal();
|
||||||
$email = $this->settings->getEmail();
|
|
||||||
$updated = new Carbon($global['last_backup']);
|
$updated = new Carbon($global['last_backup']);
|
||||||
$status = session('member') != '' ? true : false;
|
$status = session('member') != '' ? true : false;
|
||||||
$pageOptions = [
|
$pageOptions = [
|
||||||
|
@ -283,8 +282,6 @@ class SortingService
|
||||||
'themes' => $this->themes->getThemes(),
|
'themes' => $this->themes->getThemes(),
|
||||||
'apiStatus' => isset($global['externalAPI']) ? $global['externalAPI'] : 'false',
|
'apiStatus' => isset($global['externalAPI']) ? $global['externalAPI'] : 'false',
|
||||||
'dynamicRenderStatus' => isset($global['dynamicRender']) ? $global['dynamicRender'] : 'false',
|
'dynamicRenderStatus' => isset($global['dynamicRender']) ? $global['dynamicRender'] : 'false',
|
||||||
'mailOption' => $email['active'],
|
|
||||||
'mailConfig' => $email,
|
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
];
|
];
|
||||||
return $pageOptions;
|
return $pageOptions;
|
||||||
|
|
|
@ -15,17 +15,5 @@
|
||||||
"library_stats": {
|
"library_stats": {
|
||||||
"current_index": 1
|
"current_index": 1
|
||||||
},
|
},
|
||||||
"email": {
|
|
||||||
"active": "none",
|
|
||||||
"smtp": {
|
|
||||||
"domain": "",
|
|
||||||
"email": "",
|
|
||||||
"password": ""
|
|
||||||
},
|
|
||||||
"mailgun": {
|
|
||||||
"domain": "",
|
|
||||||
"api-key": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"menu": []
|
"menu": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,7 @@ section#site-features > div.features-mail {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
background: var(--secondary);
|
background: var(--secondary);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
section#site-features > div.features-mail input {
|
section#site-features > div.features-mail input {
|
||||||
|
|
|
@ -9,24 +9,16 @@ export default class Mailer {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
sendMail() {
|
sendMail(task = null, content = null) {
|
||||||
let mailData = {
|
let text = '';
|
||||||
content: 'This is a test email'
|
if (task == 'TEST') {
|
||||||
};
|
text = 'This is a test email';
|
||||||
let admin = new FipamoAdminAPI();
|
} else {
|
||||||
admin
|
text = content;
|
||||||
.sendMail(mailData)
|
|
||||||
.then(result => {
|
|
||||||
notify.alert(result.message, true);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
notify.alert(err.message, false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
testMail() {
|
|
||||||
let mailData = {
|
let mailData = {
|
||||||
content: 'This is a test email',
|
content: text,
|
||||||
mail_task: 'TESTING'
|
mail_task: task
|
||||||
};
|
};
|
||||||
let admin = new FipamoAdminAPI();
|
let admin = new FipamoAdminAPI();
|
||||||
admin
|
admin
|
||||||
|
|
|
@ -110,8 +110,8 @@ export default class SettingsIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById('send-mail')
|
.getElementById('send-test-mail')
|
||||||
.addEventListener('click', e => this.handleMailer(e));
|
.addEventListener('click', e => this.handleTestMail(e));
|
||||||
document
|
document
|
||||||
.getElementById('publish-pages')
|
.getElementById('publish-pages')
|
||||||
.addEventListener('click', e => this.handlePublished(e));
|
.addEventListener('click', e => this.handlePublished(e));
|
||||||
|
@ -160,10 +160,10 @@ export default class SettingsIndex {
|
||||||
//e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
//e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleMailer() {
|
handleTestMail() {
|
||||||
let mailer = new Mailer();
|
let mailer = new Mailer();
|
||||||
mailer.testMail();
|
//mailer.testMail();
|
||||||
//mailer.sendMail();
|
mailer.sendMail('TEST');
|
||||||
}
|
}
|
||||||
handleThemes(e) {
|
handleThemes(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
@ -185,30 +185,6 @@ export default class SettingsIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleMailOptions(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
let smtp = document.getElementById('mail-smtp');
|
|
||||||
let mailgun = document.getElementById('mail-mg');
|
|
||||||
let mail = document.querySelectorAll('.mail-option');
|
|
||||||
for (var i = 0, length = mail.length; i < length; i++) {
|
|
||||||
if (e.target.id == mail[i].id) {
|
|
||||||
mail[i].setAttribute('data-enabled', 'true');
|
|
||||||
if (e.target.id == 'option-smtp') {
|
|
||||||
smtp.setAttribute('data-enabled', 'true');
|
|
||||||
mailgun.setAttribute('data-enabled', 'false');
|
|
||||||
} else if (e.target.id == 'option-none') {
|
|
||||||
smtp.setAttribute('data-enabled', 'false');
|
|
||||||
mailgun.setAttribute('data-enabled', 'false');
|
|
||||||
} else {
|
|
||||||
smtp.setAttribute('data-enabled', 'false');
|
|
||||||
mailgun.setAttribute('data-enabled', 'true');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mail[i].setAttribute('data-enabled', 'false');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
notify.alert('Uploading Image... ', null);
|
notify.alert('Uploading Image... ', null);
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
|
@ -45,32 +45,16 @@
|
||||||
</section>
|
</section>
|
||||||
<section id="site-features" class="section-tab hide">
|
<section id="site-features" class="section-tab hide">
|
||||||
<div class="features-mail">
|
<div class="features-mail">
|
||||||
<label>SYSTEM EMAIL</label>
|
<button id="send-test-mail">
|
||||||
<div>
|
|
||||||
@if($mailOption == "option-none" or $mailOption == "")
|
|
||||||
<a href="#" class="mail-option" id="option-none" data-enabled="true">NONE</a>
|
|
||||||
@else
|
|
||||||
<a href="#" class="mail-option" id="option-none" data-enabled="false">NONE</a>
|
|
||||||
@endif
|
|
||||||
@if($mailOption == "option-mg" or $mailOption == "")
|
|
||||||
<a href="#" class="mail-option" id="option-mg" data-enabled="true">MAILGUN</a>
|
|
||||||
@else
|
|
||||||
<a href="#" class="mail-option" id="option-mg" data-enabled="false">MAILGUN</a>
|
|
||||||
@endif
|
|
||||||
@if($mailOption == "option-smtp" or $mailOption == "")
|
|
||||||
<a href="#" class="mail-option" id="option-smtp" data-enabled="true">SMTP</a>
|
|
||||||
@else
|
|
||||||
<a href="#" class="mail-option" id="option-smtp" data-enabled="false">SMTP</a>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@include('forms.mailforms')
|
|
||||||
<button id="send-mail">
|
|
||||||
<svg id="nav-menu-icon" class="icon">
|
<svg id="nav-menu-icon" class="icon">
|
||||||
<use id="nav-menu-icon" xlink:href="/assets/images/global/sprite.svg#entypo-mail-with-circle"/>
|
<use id="nav-menu-icon" xlink:href="/assets/images/global/sprite.svg#entypo-mail-with-circle"/>
|
||||||
</svg>
|
</svg>
|
||||||
<span>TEST MAIL</span>
|
<span>TEST MAIL</span>
|
||||||
</button>
|
</button>
|
||||||
|
<div>
|
||||||
|
<label>SYSTEM EMAIL</label><br />
|
||||||
|
set email settings in .env file
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="site-options">
|
<div class="site-options">
|
||||||
<div class="option-container">
|
<div class="option-container">
|
||||||
|
|
4
resources/views/mail/notify.blade.php
Normal file
4
resources/views/mail/notify.blade.php
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<div>
|
||||||
|
<strong>NOTICE</strong><br />
|
||||||
|
{{$notifyText}}<br />
|
||||||
|
</div>
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\API\PageAPIController;
|
||||||
use App\Http\Controllers\API\FileUploadAPIController;
|
use App\Http\Controllers\API\FileUploadAPIController;
|
||||||
use App\Http\Controllers\API\SettingsAPIController;
|
use App\Http\Controllers\API\SettingsAPIController;
|
||||||
use App\Http\Controllers\API\InitAPIController;
|
use App\Http\Controllers\API\InitAPIController;
|
||||||
|
use App\Http\Controllers\API\MailAPIController;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -34,3 +35,5 @@ Route::get("/v1/backup/download", [SettingsAPIController::class, 'downloadBackup
|
||||||
//init
|
//init
|
||||||
Route::post("/v1/init", [InitAPIController::class, 'setupFresh']);
|
Route::post("/v1/init", [InitAPIController::class, 'setupFresh']);
|
||||||
Route::post("/v1/restore", [InitAPIController::class, 'setupRestore']);
|
Route::post("/v1/restore", [InitAPIController::class, 'setupRestore']);
|
||||||
|
//mail
|
||||||
|
Route::post("/v1/mailer", [MailAPIController::class, 'sendNotify']);
|
||||||
|
|
Loading…
Reference in a new issue