在 Production.rb 的 ActionMailer 中使用 { host: 'localhost', port: 3000 } 部署到 VPS?



这是我第一次在生产中使用actionmailer。

早些时候,我在VPS服务器上部署了一个应用程序。我还没有给它分配一个域,所以它只是一个IP地址。

我配置了动作邮件设置,但我对这一行很好奇:config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }我可以使用服务器的Ip地址,而不是{ host: 'localhost', port: 3000 }或服务器作为本地主机后,应用程序部署与此设置?

以下是production.rb 中的设置代码
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: ENV["SMTP_ADDRESS"],
  user_name: ENV["SMTP_USER"],
  password: ENV["SMTP_PASSWORD"],
  domain: "gmail.com",
  port: 587,
  authentication: :login,
  enable_starttls_auto: true
}
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

一旦你配置了这个,你使用这些设置通过gmail服务器发送邮件。默认url将被用作网站/应用程序的域名,就像忘记密码一样。

  http://localhost:3000/forgot_password?email="fd@ds.com"

您应该将其更改为托管应用程序代码的域名或ip。Localhost仅用于开发设置。

相关内容

最新更新