The problem with scattered checks
In my Freelance Growth Engine, emails go to businesses whose problems the app found on their public websites. The risks are real: emailing someone twice, emailing someone who asked to stop, sending at 3 a.m. their time, or sending a draft nobody approved. If those rules live in five different places, one forgotten if eventually becomes a bad email.
So every send, whether a dry run or live, goes through one class. Its doc comment says it plainly: the one place that decides whether an email may leave the system, and it sends nothing itself.
Collect every reason, do not stop at the first
The gate's check() returns a result that holds all the reasons an email is blocked, not only the first one. That matters for the audit trail: when you look at a skipped email later you see everything that was wrong, not just the first failure.
public function check(OutboundEmail $e, ?CarbonImmutable $nowUtc = null): GateResult
{
$r = [];
if (EmailSettings::killSwitch()) {
$r['kill_switch'] = 'The global send switch is OFF (emergency stop).';
}
if ($e->status !== 'approved') {
$r['status'] = "Email status is “{$e->status}”, not approved.";
}
if (InboundEmail::where('lead_id', $lead->id)->where('is_automatic', false)->exists()) {
$r['replied'] = 'This person has replied, so no further automatic email is allowed.';
}
if (Suppression::isSuppressed($e->to_email)) {
$r['suppressed'] = 'The recipient is on the suppression list.';
}
// ... more rules ...
return new GateResult($r);
}
What the gate checks
- Emergency stop: a global kill switch that blocks everything instantly.
- Approval state: only emails a human approved can pass; follow-ups only after a real earlier send.
- Replies: if the person ever replied, automatic email stops.
- Verified recipient: the address must be published on the business's own contact page, so guessed addresses never receive mail.
- Suppression list: addresses and domains that opted out or bounced.
- Duplicates: no second initial email to the same lead, service or address within 30 days.
- Market and window: outreach must be enabled for that market, and the send must fall inside business hours in the recipient's timezone.
- Limits and pacing: a global daily cap, a per-campaign cap and a minimum gap between sends.
- Compliance checker: the email text is re-checked at send time, not only when it was drafted.
- Sender identity: your name and location must be set, because every email carries them.
Distinguish "never" from "not yet"
Some failures are permanent and some are temporary. A DNS blip while checking the recipient's mail domain should not condemn the email forever, so the gate treats that single case as "will retry" instead of a hard fail:
if ($failed === ['Recipient domain can receive mail']) {
$r['mail_dns'] = 'Could not confirm the recipient domain receives mail (DNS); will retry.';
} else {
$r['compliance'] = 'The email no longer passes the compliance checks.';
}
Defaults that fail safe
- Dry-run by default. The system records exactly what it would send, so you can read the evidence before anything leaves.
- Live sending needs a typed confirmation and prerequisites: SMTP configured, a sender identity, a test address, a market with outreach enabled and a recorded dry run.
- Replies never trigger an automatic response. A positive reply creates a task for a human.
Make the rule testable
A single choke point is only valuable if nothing can go around it. The test suite includes a test asserting that no other code path touches the mail provider, plus tests for each gate rule: suppression, duplicates, windows, limits and the kill switch. The project's full suite is 610 passing tests.
The takeaway
When an action is hard to undo, centralise the decision. One class that every send must pass makes the rules easy to read, easy to test and impossible to forget. Collect all failure reasons, separate temporary from permanent ones, and make the safe behaviour the default.
The wider system, including website scanning, scoring, drafting and reply handling, is in the Freelance Growth Engine case study. For backends built with this kind of care, see my Laravel development service.
Original article written by Saad Ali Khan. Code samples are illustrative and free to adapt in your own projects.