Cms: FR: Site specific email settings

Created on 17 Jul 2019  Â·  16Comments  Â·  Source: craftcms/cms

Description

Title says it all. With support for multiple domains, it doesn't make a lot of sense to have emails come from the same sender for certain types of emails. For example, if I do a password reset from siteb.com, I would get an email from the sitea.com system email address, which is quite confusing/alarming to siteb.com users.

Additional info

  • Craft version: 3.1.34
  • PHP version: N/A
  • Database driver & version: N/A
  • Plugins & versions: N/A
enhancement internationalization

Most helpful comment

That's true. So then let's scrap the idea of falling back to the primary site's values for empty fields and make the required fields required for each site. Perhaps when a new site is created it could automatically inherit the primary site's values to avoid having to manually re-enter them.

An alternative UI could be to move the 3 email setting fields into the site edit page. The question then becomes whether it is intuitive to find email related settings in the site settings.

Screenshot 2019-07-19 at 17 38 41

All 16 comments

For others trying to do this, it's actually really easy to accomplish; however, I still think it's worth leaving this issue open, as it's not very intuitive for those without a lot of experience with Craft.

In our config/app.php we just need to override the mailer component of Craft. So in the 'components' key of the app.php file (create one if it doesn't exist), you just need something like this (for Mailgun):

'mailer' => function() {
            // Get the stored email settings
            $settings = craft\helpers\App::mailSettings();

            // Override the transport adapter class
            $settings->transportType = craft\mailgun\MailgunAdapter::class;

            // Override the transport adapter settings
            if (Craft::$app->sites->getCurrentSite()->handle === 'site1') {
                $settings->transportSettings = [
                    'domain' => getenv('MG_DOMAIN_SITE1'),
                    'apiKey' => getenv('MG_API_KEY_SITE1'),
                ];
                $settings->fromEmail = getenv('SITE1_FROM_EMAIL');
                $settings->fromName = getenv('SITE1_FROM_NAME');
            } else {
                $settings->transportSettings = [
                    'domain' => getenv('MG_DOMAIN_SITE2'),
                    'apiKey' => getenv('MG_API_KEY_SITE2'),
                ];
                $settings->fromEmail = getenv('SITE2_FROM_EMAIL');
                $settings->fromName = getenv('SITE2_FROM_NAME');
            }

            // Create a Mailer component config with these settings
            $config = craft\helpers\App::mailerConfig($settings);

            // Instantiate and return it
            return Craft::createObject($config);
        },

The UI for allowing a full range of site specific email sending settings in the control panel might be tricky. What might be more feasible is to add site specific email addresses, while maintaining a single set of sending settings. I've done something similar in the Campaign plugin and have mocked up what it might look like in Craft.

Screenshot 2019-07-17 at 20 06 00

If this is a feature that the P&T team would like to add then I'd be happy to submit a pull request.

Yeah maybe. I worry that it’s going to be annoying for sites where no site-specific values are needed though.

Just fall back to the default if the settings are blank?

@theskyfloor Where is the default set?

"Site A" in which the handle is usually automatically set to default. Much like this:

"Leave blank if settings should match default site"

Screen Shot 2019-07-18 at 12 11 43 PM

So are you implying that the email settings would be required for the primary site (the first row in the table)?

Default site settings (first row) would follow the same exact convention as now. Email would be filled in with the administrator email, from name with the site name, template blank:

Screen Shot 2019-07-18 at 12 44 02 PM

My proposal was to actually replace the first 3 fields in your screenshot with the site specific email settings table. I'm not sure it makes sense to have them both.

Screenshot 2019-07-17 at 20 06 00

@putyourlightson totally! I was just posting that as an example of what Craft already does by default! I think your proposal is brilliant and spot on... the first row would just act as the current 3 fields do just in a different format... new sites default to the Primary Site unless otherwise defined :)

Got it, so we _are_ on the same page!!

That wouldn’t work for optional settings, like Email Template, where it wouldn’t be clear whether a blank value meant “no email template for this site” or “use the primary site’s template”.

That's true. So then let's scrap the idea of falling back to the primary site's values for empty fields and make the required fields required for each site. Perhaps when a new site is created it could automatically inherit the primary site's values to avoid having to manually re-enter them.

An alternative UI could be to move the 3 email setting fields into the site edit page. The question then becomes whether it is intuitive to find email related settings in the site settings.

Screenshot 2019-07-19 at 17 38 41

Same thoughts from the peanut gallery! No matter what supporting multiple domains for email seems like an essential part of offering multisite. Site settings is a pretty logical place for site specific config stuff IMO.

I really would like to see this implemented as this would just complete the multi-site offering of CraftCMS.
This should then also work with SES plugin.

I would just like to add the biggest vote of support I possibly can for getting this sorted out, please. It's a source of confusion and sometimes mistrust for site users, who are these days getting more and more careful about emails they don't recognise.

I can see that it seems to be getting pushed back from milestone to milestone, and I can see that in those milestones it competes with a lot of other great features that we're all very much looking forward to, but this is a basic service to end users, and they're what our sites (and our jobs) are all about :-)

Cheers, Andrew

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timkelty picture timkelty  Â·  3Comments

mccombs picture mccombs  Â·  3Comments

lukebailey picture lukebailey  Â·  3Comments

angrybrad picture angrybrad  Â·  3Comments

davist11 picture davist11  Â·  3Comments