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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add organization or application name in emails' From header #12837
Conversation
672acee
to
b38082b
Compare
- Add organization name in emails' from in core and admin modules - Add application name in emails' from in system module
b38082b
to
e3685bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% that i understand what PR does differently than what is already existing within the application.
In system panel we have "show advanced settings" button that is revealing the SMTP from and label:
Additionally, there is a help message for label field that states: "Email sender will be: "your-organization-name your-organization@example.org". Leave blank to use the 'Email address' as label."
If i do not set the SMTP email and label or sending mails from system panel, i get as sender: "From: change-me@example.org", apart of that, the organization seems to be correctly set when using Decidim::ApplicationMailer
.
I think it would be a much simpler fix if we could extend Decidim::Admin::ApplicationMailer
from Decidim::ApplicationMailer
, or just delete the class, as there is no mailer that has Decidim::Admin::ApplicationMailer
as ancestor.
This happens when the SMTP is configured through ENV VARS instead of the system panel, or at least that's how I could reproduce it with a new instance. Mind that the Canodrom instance isn't the only one with this behavior, this is a small sample from my email: By researching my email, I found out that even Decidim Barcelona had this bug until 2021: |
I've applied the suggestion by removing the unused class (Decidim::Admin::ApplicationMailer
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried the functionality in this PR, and i am not 100% sure is working as it should.
I have set the environment variable to: DECIDIM_MAILER_SENDER='Mimi <foobar@decidim.org>'
The obtained email sender was : foobar@decidim.org
, reading the code, i would have expected to have either Mimi <foobar@decidim.org>
, either My Organization <foobar@decidim.org>
Again, when combined with organization db settings works as intended.
In order to make it show My Organization <foobar@decidim.org>
, i had to combine set_smtp
and set_from
as follows:
def set_smtp
return if @organization.nil? || @organization.smtp_settings.blank?
# the following line has been changed
mail.from = @organization.smtp_settings["from"].presence || email_address_with_name(Decidim.config.mailer_sender, @organization.name)
mail.reply_to = mail.reply_to || Decidim.config.mailer_reply
mail.delivery_method.settings.merge!(
address: @organization.smtp_settings["address"],
port: @organization.smtp_settings["port"],
user_name: @organization.smtp_settings["user_name"],
password: Decidim::AttributeEncryptor.decrypt(@organization.smtp_settings["encrypted_password"])
) { |_k, o, v| v.presence || o }.compact_blank!
end
But this would make some specs to fail.
I have dissected the set_from
method, and my tests are calling mail.from = email_address_with_name(mail.from.first, @organization.name)
from set_from
, to no effect.
Could expand a bit the testing steps, as i am not sure what i am doing bad.
decidim-system/app/mailers/decidim/system/application_mailer.rb
Outdated
Show resolved
Hide resolved
decidim-system/spec/mailers/decidim/system/application_mailer_spec.rb
Outdated
Show resolved
Hide resolved
While reviewing, it was found that if the from was defined in the System settings, then the From header wasn't set correctly. To prevent this bug we set-up the from only once in the after_action, and make some checks if we should actually redefine this From or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just thinking that we may simplify a bit... What do u think ?
Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
@alecslupu this is ready for another review. Apart from what we've talked about, I also fixed the bug of having already defined the name in the from of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested few scenarios and seems to work properly.
LGTM
馃帺 What? Why?
All the emails sent by a Decidim instance don't show the Organization/Application name, so it's difficult to see which instance is the one sending it.
As an example, this is an email from an organization (aka Tenant) called "Comunitat Can貌drom", whose URL is https://comunitat.canodrom.barcelona/
This PR fixes this issue. In the case of the mails from System, as they could not have an Organization associated, we use the Application name config accessor.
Testing