Skip to content
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

Add email delivery error handling #192

Merged
merged 1 commit into from
May 25, 2020
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
13 changes: 10 additions & 3 deletions laravel/app/Listeners/SendAdminFileUploaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ public function handle(FileUploaded $event)
// TODO: Options to choose which admins to notify
$admin = User::where('id', 1)->first();

Mail::send('emails/admin-file-uploaded', compact('file'), function ($message) use ($admin)
try
{
$message->to($admin->email, $admin->name)->subject('New file uploaded!');
});
Mail::send('emails/admin-file-uploaded', compact('file'), function ($message) use ($admin)
{
$message->to($admin->email, $admin->name)->subject('New file uploaded!');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('warning', "Unable to send email notification, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
31 changes: 18 additions & 13 deletions laravel/app/Listeners/SendAdminRemovedShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ public function handle(SlotChanged $event)
if($event->change['status'] === 'released' && $event->change['admin_released'] === true)
{
$schedule = $event->slot->schedule;
$slot = $event->slot;
$user_email = $event->slot->user->email;
$user_name = $event->slot->user->name;
$shift_name = $event->slot->schedule->shift->name;
$shift_date = Carbon::createFromFormat('Y-m-d', $schedule->start_date)->toFormattedDateString();
$shift_time = $schedule->start_time;

$slot = $event->slot;
$user_email = $event->slot->user->email;
$user_name = $event->slot->user->name;
$shift_name = $event->slot->schedule->shift->name;
$shift_date = Carbon::createFromFormat('Y-m-d', $schedule->start_date)->toFormattedDateString();
$shift_time = $schedule->start_time;

$event_data = compact('slot', 'user_email', 'user_name', 'shift_name', 'shift_date', 'shift_time');

Mail::send('emails/admin-removed-shift', $event_data, function ($message) use ($user_email, $user_name)
{
$message->to($user_email, $user_name)->subject('Shift reschedule required!');
});
$event_data = compact('slot', 'user_email', 'user_name', 'shift_name', 'shift_date', 'shift_time');
try
{
Mail::send('emails/admin-removed-shift', $event_data, function ($message) use ($user_email, $user_name)
{
$message->to($user_email, $user_name)->subject('Shift reschedule required!');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('warning', "Unable to send email notification, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions laravel/app/Listeners/SendAdminWelcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ public function handle(UserRegistered $event)
// TODO: Options to choose which admins to notify
$admin = User::where('id', 1)->first();

Mail::send('emails/admin-welcome', compact('user'), function ($message) use ($admin)
try
{
$message->to($admin->email, $admin->name)->subject('New user registered!');
});
Mail::send('emails/admin-welcome', compact('user'), function ($message) use ($admin)
{
$message->to($admin->email, $admin->name)->subject('New user registered!');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('warning', "Unable to send email confirmation, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
26 changes: 16 additions & 10 deletions laravel/app/Listeners/SendUserFileChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@ public function handle(FileChanged $event)
{
$file = $event->file;
$user = $event->file->user;

if($file->status == 'approved')
try
{
Mail::send('emails/user-file-approved', compact('file', 'user'), function ($message) use ($user)
if($file->status == 'approved')
{
Mail::send('emails/user-file-approved', compact('file', 'user'), function ($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Uploaded File Approved');
});
}
elseif($file->status == 'denied')
{
$message->to($user->email, $user->name)->subject('Uploaded File Approved');
});
Mail::send('emails/user-file-denied', compact('file', 'user'), function ($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Uploaded File Denied');
});
}
}
elseif($file->status == 'denied')
catch (\Exception $exception)
{
Mail::send('emails/user-file-denied', compact('file', 'user'), function ($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Uploaded File Denied');
});
// Todo: Have a warning show up when the admin clicks save.
}
}
}
13 changes: 10 additions & 3 deletions laravel/app/Listeners/SendUserMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ private function forgotPassword($event)
{
$user = $event->user;

Mail::send('emails/forgot-password', compact('user'), function ($message) use ($user)
try
{
$message->to($user->email, $user->name)->subject('Your Password Reset Code');
});
Mail::send('emails/forgot-password', compact('user'), function ($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Your Password Reset Code');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('error', "Unable to send email, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
13 changes: 10 additions & 3 deletions laravel/app/Listeners/SendUserShiftConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ public function handle(SlotChanged $event)

$event_data = compact('slot', 'user_email', 'user_name', 'event_name', 'shift_name', 'start_date', 'start_time', 'end_time', 'admin_assigned');

Mail::send('emails/user-shift-confirmation', $event_data, function ($message) use ($user_email, $user_name, $shift_name)
try
{
$message->to($user_email, $user_name)->subject('Confirmation Email - ' . $shift_name . ' shift!');
});
Mail::send('emails/user-shift-confirmation', $event_data, function ($message) use ($user_email, $user_name, $shift_name)
{
$message->to($user_email, $user_name)->subject('Confirmation Email - ' . $shift_name . ' shift!');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('warning', "Unable to send email confirmation, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
}
13 changes: 10 additions & 3 deletions laravel/app/Listeners/SendUserWelcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public function handle(UserRegistered $event)
{
$user = $event->user;

Mail::send('emails/user-welcome', compact('user'), function ($message) use ($user)
try
{
$message->to($user->email, $user->name)->subject('Welcome to the Volunteer Database!');
});
Mail::send('emails/user-welcome', compact('user'), function ($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Welcome to the Volunteer Database!');
});
}
catch (\Exception $exception)
{
app('request')->session()->flash('warning', "Unable to send email confirmation, SMTP error. Please notify the administrator of this volunteer database.");
}
}
}
6 changes: 6 additions & 0 deletions laravel/resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
</div>
@endif

@if(Session::has('warning'))
<div class="general-alert alert alert-warning" role="alert">
<b>Warning:</b> {{ Session::get('warning')}}
</div>
@endif

@yield('content')
</section>

Expand Down