Emails from rails app is interpreted as two emails
ers, Whenever my application send out a plain text email to notify people of various things that email is interpreted or received by some email clients as two different emails. It works fine for gmail and comcast. Users who have get their email through a generic host like those that come with web hosting receive two emails of the same plain text email. This is terribly annoying. I would appreciate any insights. I can't launch until fixed. Please bestow your mighty wisdom! I love this site!
config/initializers/setup_mail.rb
ActionMailer::Base.default_content_type = "text/plain"
config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.xxxessment.com",
:port => 26,
:domain => "www.xxxessment.com",
:user_name => "systemadmin+xxxessment.com",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => false
}
models/actionitem_observer.rb
def after_save(actionitem)
if actionitem.responsible_id_changed? and !actionitem.responsible_id.nil?
Notifier.deliver_responsible_alert(actionitem, actionitem.responsible.email)
end
end
mailers/notifier.rb
def responsible_alert(actionitem,responsible_email)
subject "New action item assignment from xxxxx Assessment"
from "systemadmin@xxxxxsessment.com"
recipients responsible_email
sent_on Time.zone.now
content_type "text/plain"
body :actionitem => actionitem
end
views/notifier/responsible_alert.text.erb
You have been assigned Action Item #<%= @actionitem.id %> in the xxxessment system.
Action Item: <%= @actionitem.name %>
Please login in and look at开发者_JAVA百科 the My Action Items tab to find the new item.
Thank you.
Th eproblem here is an old version of the syntax. I guess this wasn't the rails 3 way of writing the code in notifier.rb and it works great.
def responsible_alert(actionitem,responsible_email)
@actionitem = actionitem
@responsible_email = responsible_email
mail(:to => @responsible_email, :subject => "New action item assignment from SXXXXXssessment") do |format|
format.html
format.text
end
end
精彩评论