简体   繁体   English

来自Rails应用程序的电子邮件被解释为两封电子邮件

[英]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. 它适用于gmail和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 config / initializers / setup_mail.rb

ActionMailer::Base.default_content_type = "text/plain"

config/environments/production.rb 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 型号/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 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 视图/通知程序/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 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. 我猜这不是在notifier.rb中编写代码的3种方式,它的效果很好。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM