用于Zoho的Rails ActionMailer配置

时间:2012-12-12 07:18:52

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

任何人都有幸配置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

有什么想法吗?

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

6 个答案:

答案 0 :(得分:30)

# 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网络进行测试。

答案 1 :(得分:3)

供参考:

我们说你的域名是abc.com 我们假设您已经默认来自'在您的邮件程序中使用不同的域名,例如

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

除非您将&#39;默认值更改为&#39;否则此将无效在您的zoho帐户上使用相同的域 所以,

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

会奏效。

答案 2 :(得分:0)

我不确定Zoho是否已更改其安全设置,但@Tyrel Richey已接受的答案对我不起作用。但是,以下是:

/config/initializers/action_mailer.rb ..

# ActionMailer email configuration
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 => true
}

其中..
:address = smtp.zoho.com
:port = 587
:domain正在开发localhost,生产中的实时网址(例如example.com

答案 3 :(得分:0)

我有邮件发送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'

<小时/> <强>参考

答案 4 :(得分:0)

这些设置对我来说很有用。

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
  }

答案 5 :(得分:0)

使用smtp.zoho.eu代替smtp.zoho.com作为地址对我有用。