Mail settings for Multisite

Is there a convenient way to use individual mail settings for each site?

At the moment, I see one way: make a Multisite behavior based on \October\Rain\Database\Traits\Multisite, and extend the \System\Models\MailSetting model with it.

Hey @igor-tv

This is an interesting idea… we’d need to pass the site ID along with queued mail as well, so the site context retained.

What is the use case for this?

We have an online store with sites for different countries on different domains. We want to send order notification emails from email addresses that match domains.

without any core team, you can do this with some small checks in method, where you sending mail.
first of all…
config/mail.php

'mailers' => [
   'domain.com' => [..],
   'domain.eu' => [..]
   'domain.sk' => [..]
]

controller where you sending e-mails

Mail::mailer(request::host())-> ....

if you wish, you can create an array of template prefixes or what ever…

$hostToPrefix = [
    'domain.com' => 'primary',
    'domain.eu' => 'europe',
    'domain.sk' => 'slovak'
];

… and, when you create an template, then use prefix for that template code,partial code, whatever you wish. Something like this…

$prefix = $hostToPrefix[request::host()];
Mail::mailer(request::host())->send($prefix . '.notifications::mail.new-order', $vars, function($message) {
    $message->to('foo@example.tld')->cc('bar@example.tld');
});

hope, will help… and… fingers crossed for update this funcionality soon :wink:

Thanks for you solution! :+1:

We’ve included this in our internal tracker to include the site ID with queued mail, and then incorporate multisite to the mail settings configuration screen.

Best regards

1 Like

We’ve added support for multisite mail settings in v3.5. It won’t be enabled by default since it triggers a different mail workflow. Here is the documentation about it:


Multisite Features

There are some core features that are not multisite-enabled by default, such as the mail configuration. You may selectively enable multisite features using the config/multisite.php file found under the features section. The following feature keys are available to use with multiple site definitions.

Feature Description
backend_mail_setting Mail configuration found in the admin panel
1 Like