mailing ¶
May 2, 2022
Initially, system was set to use Laravel Mail:: facade directly, generally to send Mailable objects to recipients.
In an effort to centralize mail processing, a MailService class was introduced. Mail sending that had previously relied on the Laravel Mail::facade now points to the MailService::send() static method.
The send() method takes incoming parameters $to, $cc, $bcc and a Mailable, and dispatches a SendEmail job to the queue. The SendEmail job will attempt to send (with the default Laravel Mail::facade) and catch/log any exceptions.
The existing Mailable objects had extant “ShouldQueue”, “Queueable” and “SerializesModels” references removed.
Mailables queued up directly for sending without a wrapper can not have their exceptions caught, which was the reason for wrapping all outbound Mailables in a single queued SendEmail job.
This initially correlated to needs outlined in CATS-848.
UPDATE May 18, 2022 ¶
CATS-923 - multiple duplicate emails.
Multiple issues stemming from ManagersMailer wrapper class.
The SendEmail job parsed multiple recipients in to a list, but was only checking is_array - a collection was passed in from ManagersMailer::send(), which caused a problem.
Patching that, there was a wrong variable being passed back from the list parsing method ($to vs $t)
Then, the Mail::to known-bug-that-isn’t-a-bug issue hit.
The Mail:: facade wrapper around swiftmailer is additive
to the underlying mailable, which is not obvious.
Mail::to('joe@example.com')->send($mailable);
Mail::to('sandy@example.com')->send($mailable);
The second email will be to sandy@ and joe@. This is non-obvious, and has hit before.
The SendEmail class clears out the recipient arrays on the mailable manually before assigning and sending. Doing it after the fact caused problems with tests that were expecting to test the mailable object after sending.
A test was added to check that sending to a collection sends a discrete number of individual emails. Test initially tried to validate discrete recipients, but the balance of Mail::fake and the SendEmail job queue combination was showing bad data in the test runs (but manual verification looks correct).