Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mankowitz's avatar

Queued emails are (intermittently) not sent, but jobs are completing successfully.

I have queued emails which work... some of the time. After a few hours, the queued jobs are created, processed and marked as done, but there is no communication with the smtp server (microsoft exchange).

Some relevant code is below:

In the controller:

      // $bcc =  list of addresses
      Mail::to('[email protected]')->bcc($bcc)->send(new NewPatientNotification("test", "email.newpatient"));

The mailable

class NewPatientNotification extends Mailable implements ShouldQueue
{
  use Queueable, SerializesModels;

  public function __construct(public string $subj, public string $viewName)
  {
    log_info("New Patient Notification Construct: sending email for ....");
  }

  public function build()
  {
    log_info("New Patient Notification Build");
    return $this->subject($this->subj)->view($this->viewName);
  }
}

The log (this one worked):

  2025-03-20 07:14:00 App\Mail\NewPatientNotification ................ RUNNING
  LOG: [user_id=0]App\Mail\NewPatientNotification@build(36): New Patient Notification Build:
  2025-03-20 07:14:02 App\Mail\NewPatientNotification ................ 2s DONE

The log (this one didn't work):

  2025-04-03 15:08:34 App\Mail\NewPatientNotification ................ RUNNING
  LOG: [user_id=0]App\Mail\NewPatientNotification@build(36): New Patient Notification Build:
  2025-04-03 15:08:34 App\Mail\NewPatientNotification ........... 56.17ms DONE

The only thing I noticed is the emails that are sent tend to take 500ms or more. The ones that don't send tend to be 100ms or less.

1 like
6 replies
vincent15000's avatar

Some months ago, I wanted to know how it's possible to be sure that an email has been sent.

Hmmm ... the application can't know if an email has been sent successfully, it can only tell you that the job is executed successfully.

tisuchi's avatar

@mankowitz Have you checked your log? Usually in laravel.log file.

If your job was processed successfully but you didn't receive the email (usually what is supposed to do), then there could be multiple reasons, e.g. SMTP connection failure... In that situation, you should have some data in the log file.

BTW, if you use SendGrid for email sending service, it might be affected by the ports, which I recently experienced.

1 like
mankowitz's avatar

I increased the logging, specifically logging on the MessageSent event as so:

  public function handle(MessageSent $event): void
  {
    log_info("MessageSent: Message-ID: " . $event->sent->getSymfonySentMessage()->getMessageId() . " SMTP Dialog: " . $event->sent->getSymfonySentMessage()->getDebug());
  }

For messages that get sent, the log contains something like this:

LOG: [user_id=0]App\Listeners\LogSentMessage@handle(479): MessageSent: Message-ID: [email protected] SMTP Dialog: [2025-04-05T00:07:59.939621-04:00] > NOOP
[2025-04-05T00:07:59.984086-04:00] < 250 2.0.0 OK
[2025-04-05T00:07:59.984156-04:00] > MAIL FROM:<[email protected]>
[2025-04-05T00:08:00.033643-04:00] < 250 2.1.0 Sender OK
[2025-04-05T00:08:00.033694-04:00] > RCPT TO:<[email protected]>
[2025-04-05T00:08:00.078450-04:00] < 250 2.1.5 Recipient OK
[2025-04-05T00:08:00.078487-04:00] > RCPT TO:<[email protected]>
[2025-04-05T00:08:00.123072-04:00] < 250 2.1.5 Recipient OK

For messages that fail to send, the SMTP dialog is empty

LOG: [user_id=0]App\Listeners\LogSentMessage@handle(479): MessageSent: Message-ID: [email protected] SMTP Dialog: ;

One thing that helped mitigate the problem is restarting the worker thread every 30 minutes.

1 like
yacine_df's avatar

Have you considered restarting the queue worker since it is a long-lived process in memory

Please or to participate in this conversation.