From bd5e6d855170539c7e02832a5cc021f62f0afcd1 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Sep 2016 07:20:10 -0700 Subject: [PATCH] Add reply-to config setting --- .env.example | 2 ++ app/Console/Commands/SendExpirationAlerts.php | 4 ++++ app/Console/Commands/SendInventoryAlerts.php | 1 + .../Controllers/AccessoriesController.php | 2 ++ .../Controllers/ConsumablesController.php | 1 + app/Http/Controllers/SettingsController.php | 2 ++ app/Http/Controllers/UsersController.php | 5 +++- app/Http/Controllers/ViewAssetsController.php | 5 +++- app/Models/Asset.php | 7 +++--- config/mail.php | 24 +++++++++++++++++++ docker.env | 2 ++ 11 files changed, 50 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 13b742f066..f9a3012b94 100644 --- a/.env.example +++ b/.env.example @@ -31,6 +31,8 @@ MAIL_PASSWORD=YOURPASSWORD MAIL_ENCRYPTION=null MAIL_FROM_ADDR=you@example.com MAIL_FROM_NAME='Snipe-IT' +MAIL_REPLYTO_ADDR=you@example.com +MAIL_REPLYTO_NAME='Snipe-IT' # -------------------------------------------- diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 83a95ead86..5c9f14644f 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -100,16 +100,20 @@ class SendExpirationAlerts extends Command if (count($expiring_assets) > 0) { + $this->info('Report sent to '.Setting::getSettings()->alert_email); \Mail::send('emails.expiring-assets-report', $asset_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Expiring Assets Report'); }); } if (count($expiring_licenses) > 0) { + $this->info('Report sent to '.Setting::getSettings()->alert_email); \Mail::send('emails.expiring-licenses-report', $license_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Expiring Licenses Report'); }); diff --git a/app/Console/Commands/SendInventoryAlerts.php b/app/Console/Commands/SendInventoryAlerts.php index 75318cd5ff..346222c430 100644 --- a/app/Console/Commands/SendInventoryAlerts.php +++ b/app/Console/Commands/SendInventoryAlerts.php @@ -50,6 +50,7 @@ class SendInventoryAlerts extends Command if (count($data['data']) > 0) { \Mail::send('emails.low-inventory', $data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Low Inventory Report'); }); diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 334c573387..9a594ccc4a 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -365,6 +365,7 @@ class AccessoriesController extends Controller Mail::send('emails.accept-accessory', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Confirm accessory delivery'); }); } @@ -483,6 +484,7 @@ class AccessoriesController extends Controller Mail::send('emails.checkin-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Confirm Accessory Checkin'); }); } diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 9557837f77..b6d57282b4 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -365,6 +365,7 @@ class ConsumablesController extends Controller Mail::send('emails.accept-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Confirm consumable delivery'); }); } diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 6bfaac6174..fc45eb8898 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -147,6 +147,7 @@ class SettingsController extends Controller try { Mail::send('emails.test', [], function ($m) { $m->to(config('mail.from.address'), config('mail.from.name')); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Test Email from Snipe-IT'); }); return 'success'; @@ -199,6 +200,7 @@ class SettingsController extends Controller if (Input::get('email_creds')=='1') { Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use ($data) { $m->to($data['email'], $data['first_name']); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Your Snipe-IT credentials'); }); } diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index ff4fef3822..34797d3fa2 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -157,6 +157,7 @@ class UsersController extends Controller Mail::send('emails.send-login', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Welcome ' . $user->first_name); }); } @@ -209,6 +210,7 @@ class UsersController extends Controller Mail::send('emails.send-login', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Welcome ' . $user->first_name); }); } @@ -533,7 +535,7 @@ class UsersController extends Controller $logaction->item_id = $license->id; $logaction->item_type = License::class; $logaction->target_id = $license->assigned_to; - $logaction->target_type = User::class; + $logaction->target_type = User::class; $logaction->user_id = Auth::user()->id; $logaction->note = 'Bulk checkin license and delete user'; $logaction->logaction('checkin from'); @@ -832,6 +834,7 @@ class UsersController extends Controller if ($newuser['email']) { Mail::send('emails.send-login', $data, function ($m) use ($newuser) { $m->to($newuser['email'], $newuser['first_name'] . ' ' . $newuser['last_name']); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Welcome ' . $newuser['first_name']); }); } diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 7687291ed7..c2d2c4cf6d 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -126,6 +126,7 @@ class ViewAssetsController extends Controller if (($settings->alert_email!='') && ($settings->alerts_enabled=='1') && (!config('app.lock_passwords'))) { Mail::send('emails.asset-canceled', $data, function ($m) use ($user, $settings) { $m->to(explode(',', $settings->alert_email), $settings->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Item Request Canceled'); }); } @@ -159,6 +160,7 @@ class ViewAssetsController extends Controller if (($settings->alert_email!='') && ($settings->alerts_enabled=='1') && (!config('app.lock_passwords'))) { Mail::send('emails.asset-requested', $data, function ($m) use ($user, $settings) { $m->to(explode(',', $settings->alert_email), $settings->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Item Requested'); }); } @@ -222,6 +224,7 @@ class ViewAssetsController extends Controller if (($settings->alert_email!='') && ($settings->alerts_enabled=='1') && (!config('app.lock_passwords'))) { Mail::send('emails.asset-requested', $data, function ($m) use ($user, $settings) { $m->to(explode(',', $settings->alert_email), $settings->site_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Asset Requested'); }); } @@ -311,7 +314,7 @@ class ViewAssetsController extends Controller // Redirect to the asset management page return redirect()->to('account/view-assets')->with('error', trans('admin/hardware/message.does_not_exist')); } - + if ($findlog->accepted_id!='') { // Redirect to the asset management page diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 5820d43197..6447abb2cc 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -152,6 +152,7 @@ class Asset extends Depreciable \Mail::send('emails.accept-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject('Confirm asset delivery'); }); } @@ -577,12 +578,12 @@ public function checkin_email() public function scopeAssetsByLocation($query, $location) { return $query->where(function ($query) use ($location) { - + $query->whereHas('assigneduser', function ($query) use ($location) { - + $query->where('users.location_id', '=', $location->id); })->orWhere(function ($query) use ($location) { - + $query->where('assets.rtd_location_id', '=', $location->id); $query->whereNull('assets.assigned_to'); }); diff --git a/config/mail.php b/config/mail.php index 64bc82d768..2f901d3ded 100644 --- a/config/mail.php +++ b/config/mail.php @@ -3,6 +3,12 @@ return [ /* + | *************************************************************************** + | DO NOT MAKE CHANGES DIRECTLY TO THIS FILE. + | + | Instead use your .env file to set your application configuration settings. + | See https://snipe-it.readme.io/docs/configuration for more info. + | |-------------------------------------------------------------------------- | Mail Driver |-------------------------------------------------------------------------- @@ -11,6 +17,7 @@ return [ | sending of e-mail. You may specify which one you're using throughout | your application here. By default, Laravel is setup for SMTP mail. | + | | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "ses", "log" | */ @@ -56,6 +63,23 @@ return [ 'from' => ['address' => env('MAIL_FROM_ADDR', null), 'name' => env('MAIL_FROM_NAME', null)], + + /* + |-------------------------------------------------------------------------- + | Global "Reply-To" Address + |-------------------------------------------------------------------------- + | + | You may wish for all e-mails sent by your application to have a different "Reply-to" + | address than the "From" address. If this is left blank, the application will use + | your MAIL_FROM information. + | + */ + + 'reply_to' => [ + 'address' => env('MAIL_REPLYTO_ADDR', env('MAIL_FROM_ADDR', null)), + 'name' => env('MAIL_REPLYTO_NAME', env('MAIL_FROM_NAME', null)) + ], + /* |-------------------------------------------------------------------------- | E-Mail Encryption Protocol diff --git a/docker.env b/docker.env index 442f5c08ed..6c39a69518 100644 --- a/docker.env +++ b/docker.env @@ -14,6 +14,8 @@ MAIL_ENV_FROM_NAME=Brady Wetherington MAIL_ENV_ENCRYPTION=tcp MAIL_ENV_USERNAME=uberbrady@gmail.com MAIL_ENV_PASSWORD=N7AqLufTZMULWHWYwJ0ZCw +MAIL_ENV_REPLYTO_ADDR=you@example.com +MAIL_ENV_REPLYTO_NAME='Snipe-IT' #SNIPE-IT Variables APP_ENV=develop