From 9986afdddb2b1b91637de1ae5c47eed8e34c40e7 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 23 Feb 2025 16:46:45 +1300 Subject: [PATCH 1/2] Allow From, Reply-To addresses to be overridden in settings table This is needed to prevent emails from being sent with incorrect addresses in the header when setting a different mailer username. --- app/mailers/admin_mailer.rb | 2 -- config/application.rb | 1 + config/initializers/mailer.rb | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index 83911456..f503629f 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -1,6 +1,4 @@ class AdminMailer < ActionMailer::Base - default :from => "nztrain@gmail.com" - def custom_email(admin,user,subject,msgbody) @user = user @msgbody = msgbody diff --git a/config/application.rb b/config/application.rb index 803fd399..5cf45eef 100644 --- a/config/application.rb +++ b/config/application.rb @@ -47,6 +47,7 @@ class Application < Rails::Application config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.default :charset => "utf-8" + config.action_mailer.default :from => "nztrain@gmail.com" ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", diff --git a/config/initializers/mailer.rb b/config/initializers/mailer.rb index 21fee7cc..16f88520 100644 --- a/config/initializers/mailer.rb +++ b/config/initializers/mailer.rb @@ -3,5 +3,7 @@ if ActiveRecord::Base.connection.table_exists?(Setting.table_name) ActionMailer::Base.smtp_settings[:user_name] = Setting.find_by_key("system/mailer/username").value if Setting.find_by_key("system/mailer/username") ActionMailer::Base.smtp_settings[:password] = Setting.find_by_key("system/mailer/password").value if Setting.find_by_key("system/mailer/password") + ActionMailer::Base.default :from => Setting.find_by_key("system/mailer/from").value if Setting.find_by_key("system/mailer/from") + ActionMailer::Base.default :reply_to => Setting.find_by_key("system/mailer/reply_to").value if Setting.find_by_key("system/mailer/reply_to") end From a3d1f093a88903d49428060662c1ccace842f654 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 23 Feb 2025 16:50:30 +1300 Subject: [PATCH 2/2] Remove some outdated references to nztrain.com --- app/views/user/admin_email.html.erb | 2 +- config/application.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/user/admin_email.html.erb b/app/views/user/admin_email.html.erb index 4a4cf38a..547d1bc5 100644 --- a/app/views/user/admin_email.html.erb +++ b/app/views/user/admin_email.html.erb @@ -13,7 +13,7 @@

<%= current_user.name %>
- Admin of nztrain.com + Admin of NZOI Training

diff --git a/config/application.rb b/config/application.rb index 5cf45eef..988a5e90 100644 --- a/config/application.rb +++ b/config/application.rb @@ -53,7 +53,7 @@ class Application < Rails::Application :address => "smtp.gmail.com", :port => 587, :authentication => :plain, - :domain => 'nztrain.com', + :domain => 'nzoi.org.nz', :user_name => 'nztrain@gmail.com', # username and password set with higher priority in settings table :password => 'training site', :enable_starttls_auto => true