【问题标题】:Can we use smtp with heroku without the SendGrid add-on?我们可以在没有 SendGrid 附加组件的情况下将 smtp 与 heroku 一起使用吗?
【发布时间】:2015-09-03 13:20:46
【问题描述】:

我正在 Heroku 中部署一个 ruby​​-on-rails 应用程序。我无法将 SendGrid 插件添加到 heroku 帐户。还有其他方法可以使用电子邮件服务吗?

【问题讨论】:

    标签: ruby-on-rails ruby heroku sendgrid add-on


    【解决方案1】:

    是的,您可以直接注册一个 SendGrid 帐户,然后使用 SMTP 详细信息。它看起来像这样:

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
        :address => "smtp.sendgrid.net",
        :port => 587,
        :domain => 'yourdomain.com',
        :user_name => ENV['SENDGRID_USERNAME'],
        :password => ENV['SENDGRID_PASSWORD'],
        :authentication => 'plain',
        :enable_starttls_auto => true 
    }
    

    SendGrid documentation 中还有一个使用 Mail gem 的示例。

    【讨论】:

      【解决方案2】:

      您可以使用您的 Gmail 帐户。 在config > environment > production.rb

      config.action_mailer.delivery_method = :smtp
      config.action_mailer.smtp_settings = {
        :address => "smtp.gmail.com",
        :port => 587,
        :domain => 'gmail.com',
        :user_name => ENV['GMAIL_USER_NAME'],
        :password => ENV['GMAIL_PASSWORD'],
        :authentication => 'plain',
        :enable_starttls_auto => true 
      }
      

      然后你必须将 GMAIL_USER_NAME 和 GMAIL_PASSWORD 设置为 Heroku 配置

      GMAIL_USER_NAME 应该是您的 gmail 域的电子邮件地址,例如。 sample@gmail.com

      【讨论】:

        猜你喜欢
        • 2013-10-29
        • 1970-01-01
        • 1970-01-01
        • 2018-10-24
        • 1970-01-01
        • 1970-01-01
        • 2021-08-09
        • 2023-03-15
        • 1970-01-01
        相关资源
        最近更新 更多