# Changing how Mautic 5 handles email from send immediately to queue

**URL:** <https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374>\
**Category:** Product Support\
**Created:** [January 2, 2024, 8:58pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374 "2024-01-02T20:58:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [January 2, 2024, 8:58pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/1 "2024-01-02T20:58:52Z")

</div>

**Your software**  
My Mautic version is: V5.0.0-rc2  
My PHP version is: 8.1  
My Database type and version is: MariadDB 10.6

When I did the original install, on Step 2 I was asked “How should emails be spooled and delivered?” Options being “Send Immediately” or “Queue”. I had selected “Send Immediately” and proceeded with the install.

Now however, after reading some posts on deliverability, I have determined that it’s in my best interest to use the Queue feature to start with.

Everything I can find in the documentation and forums say to go to **Configuration → Email Settings → How should email be handled?** and change it to Queue. But I do not have that setting anywhere in M5.

How do I change this?

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [January 2, 2024, 9:07pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/2 "2024-01-02T21:07:48Z")

</div>

![2024-01-02](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/f5697c487f5616759b6ae1276ded4dfcbd9b8f3a.png)

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 3, 2024, 2:58pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/3 "2024-01-03T14:58:16Z")

</div>

I think its Queue settings (In the left submenu)

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [January 3, 2024, 4:43pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/4 "2024-01-03T16:43:25Z")

</div>

Looked at that and I don’t think that’s it either. Not sure as there’s nothing in the docs about that.

I did find in the docs this morning that it’s saying to switch to queued sending all you need to do is set a cron job…

`bin/console messenger:consume email_transport`

If that’s the case, then what is sending them now? the 3 cron jobs I have running are:

```auto
bin/console mautic:segments:update
bin/console mautic:campaigns:update 
bin/console mautic:campaigns:trigger 

```

Do you know which one of those I would need to remove when adding in the one required for queuing in order to prevent the immediate sending?

Thanks.

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [January 3, 2024, 4:50pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/5 "2024-01-03T16:50:19Z")

</div>

I am also not understanding how that one cron job alone determines the “rate” in which the queued emails are sent out (i.e. say I only want to send 100/hour and the cron job is running every 5 minutes, that would be 8 emails per cron execution).

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [January 12, 2024, 9:04pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/6 "2024-01-12T21:04:22Z")

</div>

Is there anyone at all in the community that can assist me in getting M5 properly setup to send emails via queue?

---

<div class="post-metadata">

**Author:** ![marko008](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/marko008/32/12591_2.png) [@marko008](https://forum.mautic.org/u/marko008)\
**Post date:** [February 12, 2024, 12:19pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/7 "2024-02-12T12:19:13Z")

</div>

[https://docs.mautic.org/en/5.x/configuration/settings.html#mautic-doesn-t-use-queues-by-default](https://docs.mautic.org/en/5.x/configuration/settings.html#mautic-doesn-t-use-queues-by-default)  
You need to set queue setting scheme to doctrine and host to default  
In CRON jobs after messenger:consume email\_transport you can add --batch-limit=X to limit how many messages you want to send at once.

---

<div class="post-metadata">

**Author:** ![marko008](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/marko008/32/12591_2.png) [@marko008](https://forum.mautic.org/u/marko008)\
**Post date:** [February 12, 2024, 12:21pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/8 "2024-02-12T12:21:42Z")

</div>

don’t forget to add messenger:consume email

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [February 14, 2024, 8:30pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/9 "2024-02-14T20:30:58Z")

</div>

Thanks for the help @marko008. It’s not working just yet. I’m getting errors from the cron jobs. When I look at the logs, the first error I get is that `The "--batch-limit" option does not exist.` I tried it on both command of `messenger:consume email_transport` and then `messenger:consume email`

Also, when I don’t have the --batch-limit= on it, I get the error message that `The receiver "email_transport" does not exist.`

---

<div class="post-metadata">

**Author:** ![tcastelnau](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tcastelnau](https://forum.mautic.org/u/tcastelnau)\
**Post date:** [February 20, 2024, 11:31pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/10 "2024-02-20T23:31:19Z")

</div>

Hi guys,

I have the same issue. I can’t find a way to limit the number of emails sent every time a cron job runs.

Does anyone have an idea ?

---

<div class="post-metadata">

**Author:** ![tcastelnau](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tcastelnau](https://forum.mautic.org/u/tcastelnau)\
**Post date:** [February 21, 2024, 6:42pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/11 "2024-02-21T18:42:59Z")

</div>

I found more information. The syntax is not correct. It would be `/bin/console messenger:consume email --limit=20` which would send 20 emails each time a cron job runs.

For more options about messenger:consume, you can run :  
`php /var/www/html/bin/console messenger:consume -- help`

I got rid of the errors you mentioned but I still can’t send emails with my campaigns, although Mautic marks the emails as sent.

I have the email configured in the “Email Settings”, tested, OK.  
In “Queue Setting”, Emails are configured to “Doctrine” and “Default” for the host.

And I have a cron job that runs every 10 minutes :

\*/1 \* \* \* \* php /var/www/html/bin/console messenger:consume email --limit=1

What’s the problem?

By checking the log i can see the errors are gone.

---

<div class="post-metadata">

**Author:** ![jet1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jet1/32/13361_2.png) [@jet1](https://forum.mautic.org/u/jet1)\
**Post date:** [February 22, 2024, 12:47pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/12 "2024-02-22T12:47:32Z")

</div>

To debug, I recommend to comment out your cron commands and launch everything directly from terminal.

1. Make sure the particular email is “published” and date is set to a moment in past:

 ![2024-02-22 at 13.37](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/c/c09700fbafcc26516d81c37a0768ddd7ab5b75d7.jpeg)

1. Make sure your “queue” settings are set to doctrine  

2. run emails generator

```auto
php -d memory_limit=-1 ./bin/console mautic:broadcasts:send --batch=30 --limit=2000 --id=[YOUR-EMAIL-ID]

```

in terminal, from mautic working dir (note that you need to get your email id from mautic emails list - this arg helps to isolate sending and debugging for 1 particular campaign)

This will start feeding your queue with generated emails.  
If the process exists fast - this means you have a problem with your email generation setup. If it starts working - you will see it, it takes many seconds.

1. Run actual email sending (you can start another terminal instance for this):

```auto
php ./bin/console messenger:consume email --memory-limit=8280M -vv

```

 ![2024-02-22 at 13.45](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/f7b7cd02804da213a61748a6e449bdfad41510ef.png)

So, you need _two_ processes running when you want to send queued email campaign: first one is generating emails and putting it into queue; another one is working on the queue.

If it works from terminal, you can start moving these commands either into crontab or daemon like supervisorctl [(my preferred method).](https://forum.mautic.org/t/messenger-consume-redis-concurrency-for-better-queued-emails-performance-error-could-not-acknowledge-redis-message/30855/7)

---

<div class="post-metadata">

**Author:** ![tcastelnau](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tcastelnau](https://forum.mautic.org/u/tcastelnau)\
**Post date:** [February 22, 2024, 3:47pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/13 "2024-02-22T15:47:27Z")

</div>

Thank you so much! I followed your suggestions and I was finally able to troubleshoot and set my desired limit rate! Emails are now sent properly.

Awesome!

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [February 23, 2024, 7:20pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/15 "2024-02-23T19:20:46Z")

</div>

@jet1

Thank you for that! When running from CLI, everything seems to work.

The only thing I’m noticing is that the `php ./bin/console messenger:consume email -vv` doesn’t exit when you run it. This causes a problem when I have it running via cron, as I end up with many many instances of it running until the server bogs down to the point of locking up the server.

What do I need to do to get it to exit after each execution?

Also, the `-vv` isn’t reporting anything to the console. Is that normal?

---

<div class="post-metadata">

**Author:** ![jet1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jet1/32/13361_2.png) [@jet1](https://forum.mautic.org/u/jet1)\
**Post date:** [February 23, 2024, 8:43pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/16 "2024-02-23T20:43:04Z")

</div>

`messenger:consume` is designed to be a long-lived process so it can be run via `supervisortctl` or `systemd` (restarted from time to time, e.g. via `--memory-limit=1280M`. you can condition it to work inside cron via `--time-limit=360` arg or/and `--limit=10` (amount of emails) as well.

to see all available options, run `./bin/console help messenger:consume`

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [February 23, 2024, 9:50pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/17 "2024-02-23T21:50:53Z")

</div>

Awesome. Thank you!

---

<div class="post-metadata">

**Author:** ![hotstryker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/hotstryker/32/11147_2.png) [@hotstryker](https://forum.mautic.org/u/hotstryker)\
**Post date:** [February 24, 2024, 2:32am UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/18 "2024-02-24T02:32:34Z")

</div>

I just thought of 1 more question. All this has been done with testing Broadcast emails. What about Campaign emails? Those have been sending out immediately even without the `bin/console mautic:broadcasts:send` and `bin/console messenger:consume email` commands.

It’s probably not as critical in my situation as the likelihood of a campaign triggering that many emails at once is fairly rare, but would be nice to understand what would be needed.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [February 24, 2024, 8:30am UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/19 "2024-02-24T08:30:21Z")

</div>

Mautic brodcast send is processed in batches how often it gets called it depends on your cron config.

---

<div class="post-metadata">

**Author:** ![ahiniesta](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ahiniesta/32/1032_2.png) [@ahiniesta](https://forum.mautic.org/u/ahiniesta)\
**Post date:** [February 24, 2024, 12:06pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/20 "2024-02-24T12:06:57Z")

</div>

Hello. I have Sendgrid as delivery method, but I get:

php ./bin/console messenger:consume email --memory-limit=8280M -vv

[OK] Consuming messages from transport “email”.

// The worker will automatically exit once it has exceeded 8280M of memory or received a stop signal via the  
// messenger:stop-workers command.

// Quit the worker with CONTROL-C.

In SyncTransport.php line 37:

[Symfony\Component\Messenger\Exception\InvalidArgumentException]  
You cannot receive messages from the Messenger SyncTransport.

Exception trace:  
at /var/www/html/vendor/symfony/messenger/Transport/Sync/SyncTransport.php:37  
Symfony\Component\Messenger\Transport\Sync\SyncTransport-\>get() at /var/www/html/vendor/symfony/messenger/Worker.php:101  
Symfony\Component\Messenger\Worker-\>run() at /var/www/html/vendor/symfony/messenger/Command/ConsumeMessagesCommand.php:234  
Symfony\Component\Messenger\Command\ConsumeMessagesCommand-\>execute() at /var/www/html/vendor/symfony/console/Command/Command.php:298  
Symfony\Component\Console\Command\Command-\>run() at /var/www/html/vendor/symfony/console/Application.php:1058  
Symfony\Component\Console\Application-\>doRunCommand() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:96  
Symfony\Bundle\FrameworkBundle\Console\Application-\>doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:301  
Symfony\Component\Console\Application-\>doRun() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:82  
Symfony\Bundle\FrameworkBundle\Console\Application-\>doRun() at /var/www/html/vendor/symfony/console/Application.php:171  
Symfony\Component\Console\Application-\>run() at /var/www/html/bin/console:16

and campaign messages are not sent. Any help?

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [February 24, 2024, 6:38pm UTC](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374/21 "2024-02-24T18:38:58Z")

</div>

You do not have async consumer configured.

[Next page](https://forum.mautic.org/t/changing-how-mautic-5-handles-email-from-send-immediately-to-queue/30374.md?page=2)
