无法在Ruby on Rails中发送电子邮件

时间:2017-04-26 06:01:45

标签: ruby-on-rails

在我的应用程序中,我正在尝试发送电子邮件但无法发送。在后端它显示邮件正在进行,但在我的收件箱中邮件不会到来。 以下是我的production.rb文件 -

# require 'tls_smtp'
Rails.application.configure do

  config.cache_classes = false

  config.eager_load = false
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.assets.debug = true

  config.assets.digest = true

  config.assets.raise_runtime_errors = true

  config.action_mailer.perform_deliveries = true

  config.action_mailer.default_url_options = { host: 'mail.abc.co.in', port: 3000 }

  ActionMailer::Base.smtp_settings = {
    :address => "mail.abc.co.in",
    :port => 25,
    :user_name => "hrms@abc.co.in",
    :password => "***",
    :authentication => 'plain',
}

1 个答案:

答案 0 :(得分:0)

以下是config / environments / production.rb中的smtp设置代码:

config.action_mailer.default_url_options = { :host => 'http://abc.co.in' }

config.action_mailer.smtp_settings = {
    :address => "mail.abc.co.in",
    :port => 587,
    :domain => "abc.co.in",
    :user_name => "donotreply@abc.co.in",
    :password => "*********",
    :authentication => "plain",
    :enable_starttls_auto => true
  }

对于gmail:

config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
       :address => "smtp.gmail.com",
       :port => 587,
       :domain => "gmail.com",
       :user_name => "abc@gmail.com",
       :password => "******",
       :authentication => "plain",
       :enable_starttls_auto => true
  }