Allow to customize Sender

Created on 20 September 2023, about 1 year ago
Updated 5 March 2024, 9 months ago

Problem/Motivation

Please, allow the modification of Sender in the Mailer settings. While we can change it when actually sending the message from code, we can't do so on the settings page.

Feature request
Status

Needs work

Version

1.0

Component

User interface

Created by

🇭🇺Hungary djg_tram

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @djg_tram
  • 🇭🇺Hungary djg_tram

    From https://www.drupal.org/project/symfony_mailer/issues/3388098:

    AdamPS: However I have my doubts as

    1) The description for the site mail field says this:

    The From address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)

    2) AFAIK it isn't possible to configure sender in the GUI in other similar modules

  • 🇭🇺Hungary djg_tram

    While item 1 has its merits, I don't think item 2 would be of any importance. :-)

    Actually, the code allows it, so I can't really see any reason not to allow from the UI as well.

  • 🇫🇮Finland sokru

    One use case is to use the translated site_name configuration. The code https://git.drupalcode.org/project/symfony_mailer/-/blob/1.x/src/Address... hardcodes the Sender header as default language Site name.

  • 🇬🇧United Kingdom adamps

    The Sender should come from site configuration. If you want to change it, set "site mail" in the Basic site settings - that's exactly what that setting is for, clearly documented in the description. So why is another setting needed?

    #4 I agree is a bug. This issue GUI setting could be a workaround. The correct fix is a code change to use the correct translation (fix the code) - please can you raise a separate issue?

  • @AdamPS

    The Sender should come from site configuration. If you want to change it, set "site mail" in the Basic site settings - that's exactly what that setting is for, clearly documented in the description. So why is another setting needed?

    There are use cases outside of this, e.g. you can have more than one commerce store with different email addresses. This is a core commerce feature, see commerce_store_mail_alter

    function commerce_store_mail_alter(&$message) {
      if (substr($message['id'], 0, 9) == 'commerce_' && empty($message['params']['from'])) {
        /** @var \Drupal\commerce_store\CurrentStoreInterface $current_store */
        $current_store = \Drupal::service('commerce_store.current_store');
        $current_store = $current_store->getStore();
        if ($current_store) {
          $message['from'] = $current_store->getEmailFromHeader();
        }
      }
    }
    
  • First commit to issue fork.
  • Merge request !88Allow Sender to be set via policy. → (Open) created by longwave
  • Status changed to Needs review 9 months ago
  • 🇬🇧United Kingdom longwave UK

    I have a requirement to set a different sender for certain emails, so I needed to be able to change this via policy. I added a simple plugin to custom code to do so, I've ported it here as part of Symfony Mailer itself if this is useful.

  • Pipeline finished with Success
    9 months ago
    Total: 170s
    #98817
  • 🇨🇭Switzerland pvbergen

    I created a similar issue in 📌 Webform from address not set as sender address when using symfony_mailer Needs review .
    I also add a MailAdjuster, which automatically takes the primary from address and sets it as a sender.

    I would propose to combine the plugins to provide more configuration:
    - Take the primary from address or
    - Manually set a sender email.

    Or should we add separate adjusters?

  • 🇬🇧United Kingdom longwave UK

    I suppose a third option is to add a checkbox to FromEmailAdjuster which also sets the sender?

  • Status changed to Needs work 9 months ago
  • 🇬🇧United Kingdom adamps

    For me, this solution is a clearer UX than 📌 Webform from address not set as sender address when using symfony_mailer Needs review .

    1) If do this we need to provide a clear warning in the UI, for example in a description text. Firstly normally don't use this, set the site address instead. Secondly make sure to use a valid domain so as to avoid getting classed as spam - we could copy the wording from core.

    2) Message.php will anyway add a sender based on From. So all we need to do is set the sender to blank. This ensures that it copies the final from - rather than the current value which might later be altered by a hook.

    3) For a new feature, please add a test.

Production build 0.71.5 2024