2

我想使用 mailman 服务器将确认邮件发送到特定邮件。我尝试了很多次来做到这一点。但我没有得到任何解决方案。请建议我做这件事。

4

1 回答 1

2

这很简单:

我喜欢有一个初始化器来处理这个,就像这样:

配置/初始化程序/setup_email.rb

if Rails.env.production?
 ActionMailer::Base.smtp_settings = {
  :user_name => ENV['SENDGRID_USERNAME'],
  :password => ENV['SENDGRID_PASSWORD'],
  :domain => ENV['SENDGRID_DOMAIN'],
  :address => "smtp.sendgrid.net",
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
 }
end

然后对于生产和开发环境,您必须执行以下操作:

配置/环境/production.rb

config.action_mailer.default_url_options = { host: "http://www.example.com" }
config.action_mailer.asset_host = "http://www.example.com"

至于开发环境,我推荐你安装 mailcatcher gem:

$ gem install mailcatcher

安装后,运行 mailcatcher 命令:

$ mailcatcher

这将启用一个网页http://127.0.0.1:1080到每封电子邮件的发送位置,您将能够预览它们。只需确保您具有以下配置

配置/环境/development.rb

config.action_mailer.default_url_options = { host: "localhost:3000" }
config.action_mailer.asset_host = "http://localhost:3000"

#mailcatcher configs
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

那你应该没事!

于 2014-12-31T13:18:50.847 回答