簡體   English   中英

Rails郵件程序和sendgrid與heroku

[英]Rails mailer and sendgrid with heroku

我正在為我在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默認的郵件程序接線,這似乎不起作用。

我無法使用上面示例中使用的sendgrid-ruby gem提出解決方案。

我最終使用了sendgrids ruby-on-rails特定文檔中的THIS PAGE進行重構。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM