Override the mail method of Mailer to automatically add the foodcoop name

This commit is contained in:
Patrick Gansterer 2017-08-18 00:11:36 +02:00
parent 96a01daa34
commit 04bf994c9a
2 changed files with 13 additions and 8 deletions

View File

@ -19,7 +19,7 @@ class Mailer < ActionMailer::Base
@link = new_password_url(id: @user.id, token: @user.reset_password_token)
mail :to => @user.email,
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.reset_password.subject', :username => show_user(@user))
subject: I18n.t('mailer.reset_password.subject', username: show_user(user))
end
# Sends an invite email.
@ -28,7 +28,7 @@ class Mailer < ActionMailer::Base
@link = accept_invitation_url(token: @invite.token)
mail :to => @invite.email,
:subject => I18n.t('mailer.invite.subject')
subject: I18n.t('mailer.invite.subject')
end
# Notify user of upcoming task.
@ -37,7 +37,7 @@ class Mailer < ActionMailer::Base
@task = task
mail :to => user.email,
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.upcoming_tasks.subject')
subject: I18n.t('mailer.upcoming_tasks.subject')
end
# Sends order result for specific Ordergroup
@ -46,7 +46,7 @@ class Mailer < ActionMailer::Base
@group_order = group_order
mail :to => user.email,
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.order_result.subject', :name => group_order.order.name)
subject: I18n.t('mailer.order_result.subject', name: group_order.order.name)
end
# Notify user if account balance is less than zero
@ -55,7 +55,7 @@ class Mailer < ActionMailer::Base
@transaction = transaction
mail :to => user.email,
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.negative_balance.subject')
subject: I18n.t('mailer.negative_balance.subject')
end
def feedback(user, feedback)
@ -64,7 +64,7 @@ class Mailer < ActionMailer::Base
mail :to => FoodsoftConfig[:notification]["error_recipients"],
:from => "#{show_user user} <#{user.email}>",
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.feedback.subject', :email => user.email)
subject: I18n.t('mailer.feedback.subject', email: user.email)
end
def not_enough_users_assigned(task, user)
@ -72,7 +72,12 @@ class Mailer < ActionMailer::Base
@user = user
mail :to => user.email,
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.not_enough_users_assigned.subject', :task => task.name)
subject: I18n.t('mailer.not_enough_users_assigned.subject', task: task.name)
end
def mail(args)
args[:subject] = "[#{FoodsoftConfig[:name]}] #{args[:subject]}"
super
end
end

View File

@ -11,7 +11,7 @@ class MessagesMailer < Mailer
reply_to = "#{show_user(message.sender)} <#{message.sender.email}>"
end
mail subject: "[#{FoodsoftConfig[:name]}] " + message.subject,
mail subject: message.subject,
to: recipient.email,
from: "#{show_user(message.sender)} via #{I18n.t('layouts.foodsoft')} <#{FoodsoftConfig[:email_sender]}>",
reply_to: reply_to