Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Site specific email settings #4594

Open
Mosnar opened this issue Jul 17, 2019 · 14 comments

Comments

@Mosnar
Copy link
Contributor

commented Jul 17, 2019

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
@Mosnar

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2019

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);
        },
@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2019

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.

@brandonkelly

This comment has been minimized.

Copy link
Member

commented Jul 18, 2019

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

@theskyfloor

This comment has been minimized.

Copy link

commented Jul 18, 2019

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

@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

@theskyfloor Where is the default set?

@theskyfloor

This comment has been minimized.

Copy link

commented Jul 18, 2019

"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

@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

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

@theskyfloor

This comment has been minimized.

Copy link

commented Jul 18, 2019

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

@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

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

@theskyfloor

This comment has been minimized.

Copy link

commented Jul 18, 2019

@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 :)

@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

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

@brandonkelly

This comment has been minimized.

Copy link
Member

commented Jul 19, 2019

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”.

@putyourlightson

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2019

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

@theskyfloor

This comment has been minimized.

Copy link

commented Jul 19, 2019

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.

@brandonkelly brandonkelly added this to the 3.3 milestone Jul 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.