# Sending via REST API only sends a few emails

**URL:** <https://forum.mautic.org/t/sending-via-rest-api-only-sends-a-few-emails/33771>\
**Category:** Product Support\
**Created:** [October 10, 2024, 6:09pm UTC](https://forum.mautic.org/t/sending-via-rest-api-only-sends-a-few-emails/33771 "2024-10-10T18:09:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fisch](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/fisch/32/12946_2.png) [@fisch](https://forum.mautic.org/u/fisch)\
**Post date:** [October 10, 2024, 6:09pm UTC](https://forum.mautic.org/t/sending-via-rest-api-only-sends-a-few-emails/33771/1 "2024-10-10T18:09:18Z")

</div>

**Your software**  
My Mautic version is: 5.1.0  
My PHP version is: PHP 8.1.2-1ubuntu2.19  
My Database type and version is: 10.6.18-MariaDB-0ubuntu0.22.04.1

Hello,

I’m creating a template email and sending it to a segment of 50k recipients using the REST API /emails/ID/send endpoint. The email is created correctly, and it is then sent to about 2.700 recipients. Then it just stops.

When I open the email that was created with the API and click “send” in the web interface, the remaining 47k emails are sent without problems. When I try to send to a smaller segment (10 recipients) with the API, all emails are sent on the first try.

I have no limits and enough allowance with my SMTP provider. There are no entries in the log file.

Thank you for reading, and kind regards!

---

<div class="post-metadata">

**Author:** ![fisch](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/fisch/32/12946_2.png) [@fisch](https://forum.mautic.org/u/fisch)\
**Post date:** [October 10, 2024, 9:35pm UTC](https://forum.mautic.org/t/sending-via-rest-api-only-sends-a-few-emails/33771/2 "2024-10-10T21:35:13Z")

</div>

Solved my own problem by reading the docs. I was not aware that Mautic had switched to using queues as documented [here](https://docs.mautic.org/en/5.x/configuration/settings.html#queue-settings).

Here’s what I did:

I enabled queueing with doctrine as described in the docs and set up a worker using systemctl. This is my service file:

```auto
# /etc/systemd/system/mautic-worker.service

[Unit]
Description=Mautic Messenger Worker
After=network.target

[Service]
User=www-data
ExecStart=/usr/bin/php /opt/mautic/bin/console messenger:consume email
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
Environment=SYMFONY_ENV=prod

[Install]
WantedBy=multi-user.target

```

I started and enabled the worker with

```auto
systemctl enable mautic-worker
systemctl start mautic-worker

```

Then I added the following line to the crontab. I measured that this call takes about 2 minutes, so I gave it 4 just to be sure:

```auto
*/4 * * * * sudo -u www-data php /opt/mautic/bin/console mautic:broadcasts:send --channel=email --limit=1000 --batch=1000

```

Now everything works as intended. Just make sure the emails are published and have publish\_at date set, else they won’t get processed. Also set the unpunblish\_at date if you don’t want contacts that are added to that segment after you’ve created the email to receive it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [October 12, 2024, 9:35am UTC](https://forum.mautic.org/t/sending-via-rest-api-only-sends-a-few-emails/33771/3 "2024-10-12T09:35:38Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
