【问题标题】:Rails ActionMailer configuration for ZohoZoho 的 Rails ActionMailer 配置
【发布时间】:2012-12-12 07:18:51
【问题描述】:

谁有幸将 ActionMailer 配置为通过 Zoho 帐户发送电子邮件?

这些是我的设置:

ActionMailer::Base.smtp_settings = {
    :address              => "smtp.zoho.com",
    :port                 => 465,
    :domain               => 'example.com',
    :user_name            => 'steve@example.com',
    :password             => 'n0tmypa$$w0rd',
    :authentication       => :login
}

但是,调用 .deliver 超时:

irb(main):001:0> AdminMailer.signup_notification('asfd').deliver
Timeout::Error: Timeout::Error
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
        from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:929:in `recv_response'
        from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:552:in `block in do_start'
        from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:939:in `critical'
        from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:552:in `do_start'
        from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'

help docs 表示使用端口 465 和 SSL 身份验证。我尝试过使用和不使用:enable_starttls_auto => true,但它仍然超时。

具体来说,docs 指定以下设置:

>     Email Address: Username@yourdomain.com
>     User Name format: Username@yourdomain.com
>     Secure Connection (SSL)   Yes
>     Outgoing Mail Server Name: smtp.zoho.com
>     Outgoing Port No.: 465
>     Outgoing Mail Server requires authentication: Yes

有什么想法吗?

附言我已将 Outlook 配置为使用 help docs 中的设置,并且外发电子邮件工作正常。 telnet 到 smtp.zoho.com 465 也可以连接。

【问题讨论】:

  • 你在本地尝试吗???
  • 我是,当然 SMTP 服务器是远程的 (zoho.com)。这有关系吗?具有相同设置的电子邮件客户端(outlook)也在同一个本地主机上..
  • 不确定您是否要使用 Outlook,Microsoft 似乎不容忍从应用程序发出的邮件 - 即使是电子邮件确认等必要的事情。

标签: ruby-on-rails ruby-on-rails-3 actionmailer zoho


【解决方案1】:
# Action Mailer
ActionMailer::Base.delivery_method = :smtp  
ActionMailer::Base.smtp_settings = {            
  :address              => "smtp.zoho.com", 
  :port                 => 465,                 
  :user_name            => 'someone@somewhere.com',
  :password             => 'password',         
  :authentication       => :login,
  :ssl                  => true,
  :tls                  => true,
  :enable_starttls_auto => true    
}

这对我有用。您的设置可能很好,某些本地网络会阻止这些类型的数据包。我必须通过我的 3G 网络对其进行测试。

【讨论】:

  • 省略了delivery_method。 :S
  • 如果您收到 EOFError 消息,您可能正在尝试使用不是 Zoho 中实际帐户的发件人地址。查看此链接了解更多信息:zoho.com/mail/help/zoho-smtp.html#alink4
【解决方案2】:

仅供参考:

假设您的域是 abc.com。
假设您的邮件具有不同域的“默认发件人”,例如

  default from: "\"Elephant\" <el@ephant.com>"

将不起作用,除非您使用 zoho 帐户上的相同域更改“默认来源”。
所以,

  default from: "\"Elephant\" <el@abc.com>"

会起作用的。

【讨论】:

    【解决方案3】:

    我不确定 Zoho 是否更改了他们的安全设置,但 @Tyrel Richey 接受的答案对我不起作用。但是,以下内容会:

    /config/initializers/action_mailer.rb..

    # ActionMailer 邮件配置 ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => ENV['SMTP_ADDRESS'], :port => ENV['SMTP_PORT'], :domain => ENV['SMTP_DOMAIN'], :user_name => ENV['SMTP_USERNAME'], :password => ENV['SMTP_PASSWORD'], :authentication => :login, :enable_starttls_auto => 真 }

    在哪里..
    :address = smtp.zoho.com
    :port = 587
    :domain 是开发中的localhost,以及生产中的实时 URL(例如 example.com )

    【讨论】:

    • 您的端口应该是 465。将 ssl 和 tls 设置为 true。
    【解决方案4】:

    我像这样使用 Rails 4.2.3 发送邮件...

    # config/environments/development.rb
    Rails.application.configure do
    #...
      config.action_mailer.default_url_options = { host: 'domain' }
      config.action_mailer.smtp_settings = { address: 'smtp.zoho.com', port: 465, user_name: 'username@domain.com', password: 'mypassword', authentication: :login, ssl: true }
    end
    

    您当然也可以在生产中使用它,方法是将它添加到config/environments/production.rb

    我还将电子邮件地址设置为config/initializers/devise.rb,以便发送密码重置指令。

    config.mailer_sender = 'noreply@truhawk.com'
    


    参考文献

    【讨论】:

      【解决方案5】:

      这些设置在生产中对我有用。

      Rails.application.routes.default_url_options[:host] = 'eyehawk.io'
        config.action_mailer.default_url_options = { :host => 'eyehawk.io' }
        config.action_mailer.perform_caching = false
      
        config.action_mailer.delivery_method = :smtp
        config.action_mailer.perform_deliveries = true
        config.action_mailer.raise_delivery_errors = true
        config.action_mailer.default :charset => "utf-8"
      
        config.action_mailer.smtp_settings = {
            :address              => "smtp.zoho.com",
            :port                 => 587,
            :domain               => "zoho.com",
            :user_name            => "admin@eyehawk.io",
            :password             => ENV['SMTP_PASSWORD'],
            :authentication       => :plain,
            :enable_starttls_auto => true
        }
      

      【讨论】:

        【解决方案6】:

        使用smtp.zoho.eu 而不是smtp.zoho.com 作为地址对我有用。

        【讨论】:

          猜你喜欢
          • 2017-09-23
          • 2013-02-20
          • 1970-01-01
          • 2010-10-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多