我想使用 postman 服务器向特定邮件发送确认邮件。我多次尝试这样做。但我没有得到任何解决方案。请建议我做这件事。
最佳答案
这很简单:
我喜欢有一个初始化程序来处理这个问题,如下所示:
config/initializers/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
然后对于生产和开发环境,您必须执行如下操作:
配置/环境/生产.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
上启用一个网页,每封电子邮件都将发送到该网页,并且您可以预览它们。只需确保您具有以下配置
config/environments/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 }
那你应该没问题!
关于ruby-on-rails-4 - 如何使用 ruby on Rails 中的 mailman 服务器向特定邮件发送回复邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27706348/