From 5875b7049660968744e49c95262a03c8721b0e31 Mon Sep 17 00:00:00 2001 From: vincentdh Date: Sun, 19 Jun 2016 13:51:22 -0400 Subject: [PATCH] Add Mailgun API as mail driver Add Mailgun API as a mail driver. Can be configured from the System Settings page. --- .env.example | 3 ++ app/Http/Controllers/AppController.php | 4 ++ config/mail.php | 4 +- config/services.php | 4 +- .../views/partials/system_settings.blade.php | 50 ++++++++++++++----- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index c7cd8ea6d6..2796ba1514 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,9 @@ MAIL_FROM_ADDRESS MAIL_FROM_NAME MAIL_PASSWORD +MAILGUN_DOMAIN= +MAILGUN_SECRET= + #POSTMARK_API_TOKEN= PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address' diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index da516aeb18..5c842f3b80 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -100,6 +100,8 @@ class AppController extends BaseController $_ENV['MAIL_FROM_NAME'] = $mail['from']['name']; $_ENV['MAIL_PASSWORD'] = $mail['password']; $_ENV['PHANTOMJS_CLOUD_KEY'] = 'a-demo-key-with-low-quota-per-ip-address'; + $_ENV['MAILGUN_DOMAIN'] = $mail['mailgun_domain']; + $_ENV['MAILGUN_SECRET'] = $mail['mailgun_secret']; $config = ''; foreach ($_ENV as $key => $val) { @@ -174,6 +176,8 @@ class AppController extends BaseController $_ENV['MAIL_FROM_NAME'] = $mail['from']['name']; $_ENV['MAIL_PASSWORD'] = $mail['password']; $_ENV['MAIL_FROM_ADDRESS'] = $mail['username']; + $_ENV['MAILGUN_DOMAIN'] = $mail['mailgun_domain']; + $_ENV['MAILGUN_SECRET'] = $mail['mailgun_secret']; } $config = ''; diff --git a/config/mail.php b/config/mail.php index 6b08e8efb3..d8b32dea17 100644 --- a/config/mail.php +++ b/config/mail.php @@ -80,7 +80,7 @@ return [ | */ - 'username' => env('MAIL_USERNAME'), + 'username' => env('MAIL_USERNAME', ''), /* |-------------------------------------------------------------------------- @@ -93,7 +93,7 @@ return [ | */ - 'password' => env('MAIL_PASSWORD'), + 'password' => env('MAIL_PASSWORD', ''), /* |-------------------------------------------------------------------------- diff --git a/config/services.php b/config/services.php index 45df4553e3..99b5f0b647 100644 --- a/config/services.php +++ b/config/services.php @@ -17,8 +17,8 @@ return [ 'postmark' => env('POSTMARK_API_TOKEN', ''), 'mailgun' => [ - 'domain' => '', - 'secret' => '', + 'domain' => env('MAILGUN_DOMAIN',''), + 'secret' => env('MAILGUN_SECRET',''), ], 'mandrill' => [ diff --git a/resources/views/partials/system_settings.blade.php b/resources/views/partials/system_settings.blade.php index a16ef5d24d..debee42066 100644 --- a/resources/views/partials/system_settings.blade.php +++ b/resources/views/partials/system_settings.blade.php @@ -34,20 +34,28 @@

Email Settings

- {!! Former::select('mail[driver]')->label('Driver')->options(['smtp' => 'SMTP', 'mail' => 'Mail', 'sendmail' => 'Sendmail']) - ->value(isset($_ENV['MAIL_DRIVER']) ? $_ENV['MAIL_DRIVER'] : 'smtp') !!} - {!! Former::text('mail[host]')->label('Host') - ->value(isset($_ENV['MAIL_HOST']) ? $_ENV['MAIL_HOST'] : '') !!} - {!! Former::text('mail[port]')->label('Port') - ->value(isset($_ENV['MAIL_PORT']) ? $_ENV['MAIL_PORT'] : '587') !!} - {!! Former::select('mail[encryption]')->label('Encryption')->options(['tls' => 'TLS', 'ssl' => 'SSL']) - ->value(isset($_ENV['MAIL_ENCRYPTION']) ? $_ENV['MAIL_ENCRYPTION'] : 'tls') !!} + {!! Former::select('mail[driver]')->label('Driver')->options(['smtp' => 'SMTP', 'mail' => 'Mail', 'sendmail' => 'Sendmail', 'mailgun' => 'Mailgun']) + ->value(isset($_ENV['MAIL_DRIVER']) ? $_ENV['MAIL_DRIVER'] : 'smtp')->setAttributes(['onchange' => 'mailDriverChange()']) !!} {!! Former::text('mail[from][name]')->label('From Name') - ->value(isset($_ENV['MAIL_FROM_NAME']) ? $_ENV['MAIL_FROM_NAME'] : '') !!} + ->value(isset($_ENV['MAIL_FROM_NAME']) ? $_ENV['MAIL_FROM_NAME'] : '') !!} {!! Former::text('mail[username]')->label('Email') ->value(isset($_ENV['MAIL_USERNAME']) ? $_ENV['MAIL_USERNAME'] : '') !!} - {!! Former::password('mail[password]')->label('Password') - ->value(isset($_ENV['MAIL_PASSWORD']) ? $_ENV['MAIL_PASSWORD'] : '') !!} +
+ {!! Former::text('mail[host]')->label('Host') + ->value(isset($_ENV['MAIL_HOST']) ? $_ENV['MAIL_HOST'] : '') !!} + {!! Former::text('mail[port]')->label('Port') + ->value(isset($_ENV['MAIL_PORT']) ? $_ENV['MAIL_PORT'] : '587') !!} + {!! Former::select('mail[encryption]')->label('Encryption')->options(['tls' => 'TLS', 'ssl' => 'SSL']) + ->value(isset($_ENV['MAIL_ENCRYPTION']) ? $_ENV['MAIL_ENCRYPTION'] : 'tls') !!} + {!! Former::password('mail[password]')->label('Password') + ->value(isset($_ENV['MAIL_PASSWORD']) ? $_ENV['MAIL_PASSWORD'] : '') !!} +
+
+ {!! Former::text('mail[mailgun_domain]')->label('Mailgun Domain') + ->value(isset($_ENV['MAILGUN_DOMAIN']) ? $_ENV['MAILGUN_DOMAIN'] : '') !!} + {!! Former::text('mail[mailgun_secret]')->label('Mailgun Private Key') + ->value(isset($_ENV['MAILGUN_SECRET']) ? $_ENV['MAILGUN_SECRET'] : '') !!} +
{{-- Former::actions( Button::primary('Send test email')->small()->withAttributes(['onclick' => 'testMail()']), '  ' ) --}}
@@ -57,7 +65,8 @@ var db_valid = false var mail_valid = false - + mailDriverChange(); + function testDatabase() { var data = $("form").serialize() + "&test=db"; @@ -78,6 +87,23 @@ return db_valid; } + function mailDriverChange() { + if ($("select[name='mail[driver]'").val() == 'mailgun') { + $("#standardMailSetup").hide(); + $("#standardMailSetup").children('select,input').prop('disabled',true); + $("#mailgunMailSetup").show(); + $("#mailgunMailSetup").children('select,input').prop('disabled',false); + + } else { + $("#standardMailSetup").show(); + $("#standardMailSetup").children('select,input').prop('disabled',false); + + $("#mailgunMailSetup").hide(); + $("#mailgunMailSetup").children('select,input').prop('disabled',true); + + } + } + function testMail() { var data = $("form").serialize() + "&test=mail";