【问题标题】:Rails mailer and sendgrid with herokuRails 邮件程序和 sendgrid 与 heroku
【发布时间】:2017-01-07 19:30:18
【问题描述】:

我正在为我在 heroku 上托管的应用程序添加电子邮件功能。

以下是相关文件:

app/mailers/user_actions_mailer.rb

def add_user_action(action_params)
        @action_params = action_params
        from = Email.new(email: 'marklocklear@blah.org')
        subject = 'You have been notified'
        to = Email.new(email: 'my_user@gmail.com')
        content = Content.new(type: 'text/html', value: "test")
        mail = Mail.new(from, subject, to, content)

        sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
        response = sg.client.mail._('send').post(request_body: mail.to_json)
    end

这工作正常,我可以用它发送电子邮件。但是,我的问题在于上面的“内容”变量。我希望内容使用 app/views/user_actions_mailer/add_user_action.html.erb 中的 rails 标准邮件模板。

我创建了这个文件/文件夹,但我不确定如何将内容指向这个位置。我尝试不将内容传递给 Mail.new 功能,希望这可能会触发 Rails 默认邮件程序接线,这似乎不起作用。

【问题讨论】:

    标签: ruby-on-rails heroku sendgrid


    【解决方案1】:

    使用我上面的示例使用的 sendgrid-ruby gem,我无法为此提出解决方案。

    我最终使用来自sendgrids ruby​​-on-rails 特定文档的 THIS PAGE 进行重构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2016-12-08
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多