An intelligent script designed to send Mautic emails in a controlled manner, ensuring efficient email delivery and providing real-time feedback. Created and maintained by Taylor Selden.
MauticSmartSend
is designed to enhance the way Mautic sends emails by giving you more control and feedback in real-time. While Mautic comes with its own built-in method for sending emails through the mautic:emails:send
command/cron job, our script offers an intelligent alternative with several advantages.
Why use MauticSmartSend?
- Granular Control: Decide exactly how many emails are sent in each batch (via
MESSAGE_LIMIT
), and define the pause duration between batches (usingSLEEP_TIME
). - Real-time Feedback: Get live updates on the number of emails in the spool, the ones currently being sent, remaining emails, and an estimated finish time.
- Flexibility: You can schedule this script to run as frequently as you desire, even every minute, using a cron job. This ensures that emails are sent out promptly and efficiently, and Mautic will only be invoked if there are mails that need to be sent.
Intended Use:
Replace Mautic's default mautic:emails:send
cron job with MauticSmartSend
. By doing so, you'll optimize the email delivery process, reduce the chances of server overloads, avoid getting rate limited, and get immediate feedback on the email sending status.
-
Download the Script:
Usewget
to download the script directly from the GitHub repository.wget https://raw.githubusercontent.com/mrlazycoder/mautic-smartsend/main/mautic_smartsend.sh
-
Ensure you have the necessary dependencies installed:
- PHP (version 7.4 or above is recommended)
- Mautic (tested with version 4.4.1)
-
Make the Script Executable:
Once the script is downloaded, you'll need to make it executable.chmod +x mautic_smartsend.sh
-
Configuration:
Before you can run the script, you'll need to open it in your favorite text editor and configure some settings at the top of the script. See details below in the Configuration section.nano mautic_smartsend.sh
-
Move it to your desired directory.
Inside the script, there are some constants which you should modify based on your environment:
-
PHP_EXEC
: The path to the PHP executable on your server. This is used to run PHP commands from the script.
Default:/usr/local/bin/php
-
SPOOL_DIR
: This is the directory where Mautic spools or queues the emails. It specifies the location from which the script will fetch the emails and process them.
Default:/home/username/public_html/mautic/var/spool
-
BIN_DIR
: This is the directory containing the Mautic console. The Mautic console is used by the script to send the emails, among other tasks.
Default:/home/username/public_html/mautic/bin
-
LOCK_FILE
: This is a temporary lock file's location. It is used to ensure that only one instance of the script runs at any given time, preventing any potential conflicts or errors.
Default:/tmp/mautic_email_sender.lock
-
MESSAGE_LIMIT
: This constant defines the maximum number of emails the script will process and send in a single cycle or iteration. 14 is the rate limit for Amazon SES. Default:14
-
SLEEP_TIME
: After sending a batch of emails, the script will wait or "sleep" for a certain period (in seconds) before proceeding to the next batch. This is to prevent exceeding the email service's rate limit. Default:1
Execute the script from the terminal and get live feedback:
./mautic_smartsend.sh
Run in silent mode (i.e. for a cron job):
./mautic_smartsend.sh -s
- Silent Mode: Run the script without any terminal output.
- Rate Limiting: Adjust the sending rate based on your mail server's performance.
- Locking Mechanism: Ensures only one instance of the script is running. You can run as often as you like via cron and multiple executions will be avoided.
Q: Why am I seeing an error regarding the lock file?
A: Ensure that the lock file directory is writable by the user running the script.
For a detailed history of changes made to this project, see the CHANGELOG.md file.
Feel free to fork the repository and submit pull requests. All contributions are welcome!
This project is licensed under the GNU General Public License v3.0 (GPLv3) - see the LICENSE.txt file for details.
The GNU GPLv3 is a free, copyleft license for software and other kinds of works. This license ensures that the software remains free and open-source, and any derivative works must also be under the same license. It promotes the distribution and modification of the software while ensuring that it remains free.
For more information about the GNU GPLv3, please visit the official GNU website.
- The entire Mautic community for their amazing software that I use on a daily basis.