Skip to content

Allow From, Reply-To addresses to be overridden in settings table#272

Closed
Holmes98 wants to merge 2 commits intomasterfrom
change-mailer-address
Closed

Allow From, Reply-To addresses to be overridden in settings table#272
Holmes98 wants to merge 2 commits intomasterfrom
change-mailer-address

Conversation

@Holmes98
Copy link
Member

@Holmes98 Holmes98 commented Feb 23, 2025

I've changed the website to send emails using train@nzoi.org.nz, but this currently causes emails to be sent with incorrect headers:

X-Google-Original-From: nztrain@gmail.com
Reply-To: nztrain@gmail.com

This would also allow setting the sender's display name, e.g. "NZOI Training" <train@nzoi.org.nz>; currently Gmail just shows the sender as "train" or "nztrain".

This is needed to prevent emails from being sent with incorrect
addresses in the header when setting a different mailer username.
@coveralls
Copy link

Coverage Status

coverage: 37.529% (+0.006%) from 37.523%
when pulling a3d1f09 on change-mailer-address
into 51571c5 on master.

@tom93
Copy link
Contributor

tom93 commented Feb 23, 2025 via email

@Holmes98
Copy link
Member Author

I don't know why, but maybe there are cases where the SMTP username isn't the same as the email address.

I guess we could still set the fields from system/mailer/username to avoid repetition, though then you wouldn't be able to set the display name and I didn't want to overcomplicate things.

@Holmes98
Copy link
Member Author

Actually, it's probably just because Action Mailer has other delivery methods than SMTP (e.g. sendmail).

@tom93
Copy link
Contributor

tom93 commented Feb 23, 2025 via email

@Holmes98
Copy link
Member Author

Yeah, I just changed the system/mailer settings, but those are only used for SMTP authentication.

For emails from Devise, the from/reply_to parameters seem to be set from the mailer_sender setting (but only if you don't set the default from/reply_to parameters; I still left it in though as it seems to break the specs if commented out):

config.mailer_sender = "nztrain@gmail.com"

Emails from the admin panel currently use this (which I removed in this PR):

default :from => "nztrain@gmail.com"

@tom93
Copy link
Contributor

tom93 commented Feb 23, 2025 via email

@Holmes98
Copy link
Member Author

Sure.

@tom93
Copy link
Contributor

tom93 commented Mar 6, 2025

I'm mostly done (branch "pr/remove-hard-coded-nztrain-email" of my fork, commits).

One question is how the settings should work. I would strongly prefer that in the simplest case (where the admin doesn't want to set a pretty display name), the email would only have to be configured in one setting. Here are the options I like:

A. "system/mailer/email" for auth and default "From:", setting "system/mailer/from" to override "From:" (may contain a display name).

B. "system/mailer/email" for auth and "From:", "system/mailer/display_name" (optional) added to "From:".

(For both options, a migration could rename "system/mailer/username" to "system/mailer/email".)

Also, is Reply-To useful, or was it just a workaround?

@Holmes98
Copy link
Member Author

Holmes98 commented Mar 6, 2025

That looks reasonable. I'm fine with either of those options, or even just hardcoding the display name to "NZOI Training", since there are already hardcoded references to that elsewhere on the site.

Note that config.action_mailer.default() is broken[1], so we must use default_options=.

Nice find, I guess that's why the specs were breaking for me earlier.

Reply-To was mostly a workaround. I could see it maybe being useful for redirecting responses to an mailbox that's actually monitored, but it's probably not important.

@tom93
Copy link
Contributor

tom93 commented Mar 19, 2025

I implemented the hard-coded display name and opened #273.
Are you okay with using that and dropping this PR?

@Holmes98 Holmes98 closed this Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants