Cms: Multiple Email Accounts / Multiple Sender Addresses

Created on 5 May 2020  Â·  4Comments  Â·  Source: craftcms/cms

Hello,
is there a way to have multiple Email accounts? In the Admin Email settings domain.tld/admin/settings/email it looks like I can only use one account for sending emails. What's the best practice for providing multiple email addresses?

For example I have two different emails. For each email the user should be able to answer to 2 different email addresses. Is it better to use two different email accounts, or just one email account and two different Reply-To header in the emails which are sent to the users?

I use Craft CMS 3.3.20.1.

enhancement site development

Most helpful comment

It’s currently not possible to specify multiple senders from Settings → Email, however you can do it by overriding the system mailer component in config/app.php:

return [
    'components' => [
        'mailer' => function() {
            // Instantiate the Mailer component with the system settings
            $settings = craft\helpers\App::mailSettings();
            $mailer = Craft::createObject(craft\helpers\App::mailerConfig($settings));

            // Override the `from` property with multiple senders
            $mailer->from = [
                '[email protected]' => 'Name A',
                '[email protected]' => 'Name B',
            ];

            // Return it
            return $mailer;
        },
    ],
];

(If you’d prefer to have multiple Reply-To emails instead, set replyTo instead of from on the mailer.)

We can consider adding support for multiple From/Reply-To emails alongside #4594, so I’ll leave this open and put it on the 3.5 list.

All 4 comments

It’s currently not possible to specify multiple senders from Settings → Email, however you can do it by overriding the system mailer component in config/app.php:

return [
    'components' => [
        'mailer' => function() {
            // Instantiate the Mailer component with the system settings
            $settings = craft\helpers\App::mailSettings();
            $mailer = Craft::createObject(craft\helpers\App::mailerConfig($settings));

            // Override the `from` property with multiple senders
            $mailer->from = [
                '[email protected]' => 'Name A',
                '[email protected]' => 'Name B',
            ];

            // Return it
            return $mailer;
        },
    ],
];

(If you’d prefer to have multiple Reply-To emails instead, set replyTo instead of from on the mailer.)

We can consider adding support for multiple From/Reply-To emails alongside #4594, so I’ll leave this open and put it on the 3.5 list.

🤞 this will be in 3.5, just realized I need it for an up and coming site launch...

How is the status on this one? We’re launching a multi-site installation where all (sister-)sites have a different email address next to the contact form and it would be great to be able to send from these addresses instead of the one defined in email settings.

@jannisborgers Didn’t make the cut for 3.5 unfortunately. See my last comment for an example of how you can override the mailer component though.

Was this page helpful?
0 / 5 - 0 ratings