FR: Site specific email settings #8709
-
DescriptionTitle 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
|
Beta Was this translation helpful? Give feedback.
Replies: 19 comments 7 replies
-
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 '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);
}, |
Beta Was this translation helpful? Give feedback.
-
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. If this is a feature that the P&T team would like to add then I'd be happy to submit a pull request. |
Beta Was this translation helpful? Give feedback.
-
Yeah maybe. I worry that it’s going to be annoying for sites where no site-specific values are needed though. |
Beta Was this translation helpful? Give feedback.
-
Just fall back to the default if the settings are blank? |
Beta Was this translation helpful? Give feedback.
-
@theskyfloor Where is the default set? |
Beta Was this translation helpful? Give feedback.
-
"Site A" in which the handle is usually automatically set to default. Much like this: "Leave blank if settings should match default site" |
Beta Was this translation helpful? Give feedback.
-
So are you implying that the email settings would be required for the primary site (the first row in the table)? |
Beta Was this translation helpful? Give feedback.
-
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: |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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 :) |
Beta Was this translation helpful? Give feedback.
-
Got it, so we are on the same page!! |
Beta Was this translation helpful? Give feedback.
-
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”. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I really would like to see this implemented as this would just complete the multi-site offering of CraftCMS. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Yes, me again, because this is still a big issue for my client ... Although this has all gone a bit quiet, I still think it's a basic need: a client of mine has related businesses that use different domains, and they really don't think it's a good look when people receive an email but don't recognise where it came from. My client really doesn't like it, and I agree with them. We really should be able to specify that system emails come from a site, rather than from the system, which means specific email addresses for each site, and the option of different templates for each site (for branding, etc). Doesn't that make sense? I recommend Craft to my clients because of the usually superb localisation features, so this issue just doesn't sit well. Along with the lack of site-specific Commerce stores, of course, which has lost me several jobs and is also taking a long time to be addressed. I haven't given up on either of these enhancements, though, so can anyone confirm whether this will ever be worked on? Thanks! |
Beta Was this translation helpful? Give feedback.
-
As it isn't mentioned above, another use case I would find useful here is the ability to set the Transport Type via Environment Variable (i.e. It seems most other settings on the Email Settings page allow this and would allow for better customization in development workflows where you may want to override the default Email Settings to use, say, DDEV's Mailhog integration (which requires SMTP, so if you are using anything other than SMTP having local settings to use Mailhog requires additional steps) |
Beta Was this translation helpful? Give feedback.
-
Added this for Craft 5.6 🎉 (#16187). Also added the ability to track which site users should be primarily affiliated with, so site-specific email settings will be factored in when sending emails from the control panel as well. (#16174) |
Beta Was this translation helpful? Give feedback.
Added this for Craft 5.6 🎉 (#16187).
Also added the ability to track which site users should be primarily affiliated with, so site-specific email settings will be factored in when sending emails from the control panel as well. (#16174)