{"id":236,"date":"2024-01-11T21:43:09","date_gmt":"2024-01-11T21:43:09","guid":{"rendered":"https:\/\/otb.agency\/?p=236"},"modified":"2024-01-13T21:49:28","modified_gmt":"2024-01-13T21:49:28","slug":"how-to-setup-mautic-5-and-amazon-ses","status":"publish","type":"post","link":"https:\/\/otb.agency\/?p=236","title":{"rendered":"How to setup Mautic 5 and Amazon SES"},"content":{"rendered":"\n<p>Learn how to integrate Mautic 5 and Amazon SES to send emails at scale.<\/p>\n\n\n\n<p>After almost two years, the team at Mautic has released one of the biggest updates to the marketing automation platform to date. With support for PHP 8.1 and migrating to the Symfony 5 framework, many things need updating as well. One of the things that we will touch on in this article today is changing the configuration to configure Mautic 5 and Amazon SES for fast and scalable email sending.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Mautic 5 and Amazon SES configuration<\/h2>\n\n\n\n<p>From now on, instead of configuring emails in the old form where you are entering your SES credentials, Mautic now uses Symfony&#8217;s DSN (Data Source Name) format and their Mailer package. <\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a4ab20e516b7&quot;}\" data-wp-interactive=\"core\/image\" class=\"wp-block-image size-large wp-lightbox-container\"><img data-dominant-color=\"e5e7ee\" data-has-transparency=\"true\" style=\"--dominant-color: #e5e7ee;\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"291\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35-1024x291.png\" alt=\"Mautic 5 Email configuration\" class=\"wp-image-242 has-transparency\" srcset=\"https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35-1024x291.png 1024w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35-300x85.png 300w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35-768x218.png 768w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35-1536x437.png 1536w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.49.35.png 1772w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on-async--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Mautic 5 Email configuration<\/figcaption><\/figure>\n\n\n\n<p>Before configuring the settings, we need to <a href=\"https:\/\/github.com\/symfony\/amazon-mailer\" data-type=\"link\" data-id=\"https:\/\/github.com\/symfony\/amazon-mailer\" target=\"_blank\" rel=\"noreferrer noopener\">install <em>symfony\/amazon-mailer<\/em><\/a> package that will allow us to communicate with Amazon SES API.<\/p>\n\n\n\n<p>Go to your terminal and connect to your Mautic server. Next, navigate to your Mautic installation and run this command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>composer require symfony\/amazon-mailer<\/code><\/pre><\/div>\n\n\n\n<p>This package will allow us to set up the DSN in configuration to ses+api scheme needed for sending emails.<\/p>\n\n\n\n<p>After that, we can go back to Mautic configuration and configure Email DSN as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scheme: ses+api<\/li>\n\n\n\n<li>Host: default<\/li>\n\n\n\n<li>Port: leave blank<\/li>\n\n\n\n<li>Path: leave blank<\/li>\n\n\n\n<li>User: ACCESS_TOKEN (from your SES credentials)<\/li>\n\n\n\n<li>Password: SECRET (from your SES credentials)<\/li>\n\n\n\n<li>Options: click Add a value\n<ul class=\"wp-block-list\">\n<li>Label: region<\/li>\n\n\n\n<li>Value: us-east-1 (the SES region you are using)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>In the end, you will have the form looking like this<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"eaebf0\" data-has-transparency=\"true\" style=\"--dominant-color: #eaebf0;\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"381\" src=\"https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40-1024x381.png\" alt=\"Mautic 5 and Amazon SES\" class=\"wp-image-243 has-transparency\" srcset=\"https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40-1024x381.png 1024w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40-300x112.png 300w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40-768x285.png 768w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40-1536x571.png 1536w, https:\/\/otb.agency\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-10-at-21.59.40.png 1754w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Mautic 5 Amazon SES configuration<\/figcaption><\/figure>\n\n\n\n<p>Mautic will send the emails via SES using immediate delivery as it&#8217;s the default way of sending messages. If you plan on sending a higher volume of emails, it&#8217;s better to use the queuing mechanisms that are designed to handle those workloads. <br>Our personal favorite is using Redis as queueing mechanism. This feature was long awaited in Mautic and starting with version 5 that relies on Symfony 5 framework, we can finally use wide variety of queues, including Redis and even Amazon SQS. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redis configuration<\/h2>\n\n\n\n<p>If you haven&#8217;t already, you can read an in-depth article about how to configure Mautic and Redis.<\/p>\n\n\n\n<p>Now, we will assume you already have a Redis server, either as a service on your server or as a separate instance. The configuration is easy. Once again, we are going to use DSN to configure the Email and SMS queue. <\/p>\n\n\n\n<p>Install the <em>symfony\/redis-messenger<\/em> package.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>composer require symfony\/redis-messenger<\/code><\/pre><\/div>\n\n\n\n<p>Then, in Mautic configuration, go to the Queue Settings and look for the first form, <strong>Queue for email (SMS and push messages)<\/strong>.<\/p>\n\n\n\n<p>Here you have to define at least three settings in case you are using the default Redis installation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scheme: redis<\/li>\n\n\n\n<li>Host: 127.0.0.1 (or the IP address of your Redis instance)<\/li>\n\n\n\n<li>Port: 6379<\/li>\n<\/ul>\n\n\n\n<p>Hit save and close and you are good to go. <\/p>\n\n\n\n<p><strong>UPDATE<\/strong><\/p>\n\n\n\n<p>From now on, Mautic is utilizing the workers from Symfony, meaning that you don&#8217;t have to set up a cron job to send emails. In fact, you might end up overloading the server since every minute you will spawn a new service for picking up emails from the queue and processing them. So instead of creating new cron, ignore this and set up a daemon on your server. <\/p>\n\n\n\n<p><s>Lastly, you need to update your cronjobs to enable sending emails. <\/s><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>* * * * * php \/path\/to\/mautic\/bin\/console messenger:consume email<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Using Supervisor to Send emails with Mautic 5 and Amazon SES<\/h2>\n\n\n\n<p>For running our workers in the background, we will utilize the <strong>supervisor<\/strong>. It&#8217;s a program that allows us to spawn processes in the background and ensure that they are running if they are terminated. This allows us to have an always running worker that will check for new emails in the queue and send them. <\/p>\n\n\n\n<p>Here we will cover installing and configuring supervisor on Ubuntu 22.04.<\/p>\n\n\n\n<p>First, connect to your server via SSH and run following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo apt update && sudo apt install supervisor<\/code><\/pre><\/div>\n\n\n\n<p>After the installation is completed, the service should run automatically. You can verify that by running the command: <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo systemctl status supervisor<\/code><\/pre><\/div>\n\n\n\n<p>Check for the following output:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>systemctl status supervisor\n\u25cf supervisor.service - Supervisor process control system for UNIX\n     Loaded: loaded (\/lib\/systemd\/system\/supervisor.service; enabled; vendor preset: enabled)\n     Active: active (running) since Sat 2024-01-13 20:24:30 UTC; 39min ago\n       Docs: http:\/\/supervisord.org\n   Main PID: 807 (supervisord)\n      Tasks: 14 (limit: 4556)\n     Memory: 718.9M<\/code><\/pre><\/div>\n\n\n\n<p>After the installation, we can move and configure our daemon.<\/p>\n\n\n\n<p>We are spawning the new workers by creating the config file in the supervisor. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo nano \/etc\/supervisor\/conf.d\/mautic-mail.conf<\/code><\/pre><\/div>\n\n\n\n<p>Next, paste and adjust the following code to match your Mautic installation:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>[program:mautic-mail]\ndirectory=\/var\/www\/path\/to\/mautic\/instance\ncommand=php bin\/console messenger:consume email\nprocess_name=%(program_name)s_%(process_num)02d\nautostart=true\nautorestart=true\nuser=www-data\nredirect_stderr=true\nnumprocs=1\nstdout_logfile=\/var\/log\/mautic\/mautic-mail-daemon.log<\/code><\/pre><\/div>\n\n\n\n<p>Let&#8217;s explain this in key details:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>[program:mautic-mail]\n<\/code><\/pre><\/div>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>program: mautic-mail<\/strong> is simply the unique name of your daemon. You can set it to anything you&#8217;d like<\/li>\n\n\n\n<li><strong>directory<\/strong> tells us where your Mautic installation is located<\/li>\n\n\n\n<li><strong>command <\/strong>&#8211; this is the actual command. If you have multiple PHP versions installed on your server, you can use the alias for the version you are using (php8.1, php8.0, or leave php if it&#8217;s the correct version)<\/li>\n\n\n\n<li><strong>autostart<\/strong> and <strong>autorestart <\/strong>directives allow us to restart the process in case it&#8217;s stopped.<\/li>\n\n\n\n<li><strong>user<\/strong> is the actual user under which your mautic instance is running. By default, it&#8217;s www-data<\/li>\n<\/ol>\n\n\n\n<p>After updating the config file with your settings, save the file and exit the editor. Next, we will instruct the supervisor to check for new config files.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo supervisorctl reread<\/code><\/pre><\/div>\n\n\n\n<p>If everything is okay, you should see the following output:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Output\nmautic-mail: available<\/code><\/pre><\/div>\n\n\n\n<p>After seeing the correct output, we can update the supervisor to run our worker.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo supervisorctl update<\/code><\/pre><\/div>\n\n\n\n<p>And once again, if everything is okay, we will see the following output;<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Output\nmautic-mail: added process group<\/code><\/pre><\/div>\n\n\n\n<p>To verify that the worker is running, we can enter the supervisor by running <strong>supervisorctl<\/strong> in your terminal.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo supervisorctl<\/code><\/pre><\/div>\n\n\n\n<p>Right after the launch, supervisor will list the running processes:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Output\nmautic-mail                      RUNNING    pid 23274, uptime 0:03:12\nsupervisor&gt;<\/code><\/pre><\/div>\n\n\n\n<p>To exit supervior, type <strong>quit<\/strong> and we are back to our terminal.<\/p>\n\n\n\n<p>And that&#8217;s it. If you have followed everything, your Mautic will be configured and sending emails with Amazon SES. <\/p>\n\n\n\n<p>Combined with Redis, you will have a truly scalable solution that will handle sending thousands of emails without any problems. <\/p>\n\n\n\n<div class=\"wp-block-group alignfull has-text-color has-background is-layout-flow wp-block-group-is-layout-flow\" style=\"color:#000000;background-color:#ffffff\">\n<div style=\"height:64px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\" id=\"schedule-a-visit\" style=\"font-size:clamp(18.959px, 1.185rem + ((1vw - 3.2px) * 1.082), 30px);line-height:1.15\"><strong>Need help configuring your Mautic instance?<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-03627597 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-50\"><a class=\"wp-block-button__link has-text-color has-background wp-element-button\" href=\"mailto:mautic@otb.agency\" style=\"border-radius:50px;color:#ffffff;background-color:#000000\">Drop us an email<\/a><\/div>\n<\/div>\n\n\n\n<div style=\"height:64px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to integrate Mautic 5 and Amazon SES to send emails at scale. After almost two years, the team at Mautic has released one of the biggest updates to the marketing automation platform to date. With support for PHP 8.1 and migrating to the Symfony 5 framework, many things need updating as well. One [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-mautic"],"acf":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Goran \u0106ulibrk","author_link":"https:\/\/otb.agency\/?author=1"},"uagb_comment_info":49,"uagb_excerpt":"Learn how to integrate Mautic 5 and Amazon SES to send emails at scale. After almost two years, the team at Mautic has released one of the biggest updates to the marketing automation platform to date. With support for PHP 8.1 and migrating to the Symfony 5 framework, many things need updating as well. One&hellip;","_links":{"self":[{"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/otb.agency\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":6,"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/otb.agency\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/otb.agency\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/otb.agency\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/otb.agency\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}