etewiah / pwb-for-heroku

A Rails website using the property-web-builder gem and ready to be deployed to heroku
20 stars 30 forks source link

Configuring Sendgrid for heroku #10

Closed etewiah closed 6 years ago

etewiah commented 6 years ago

From @cesarem:

I created a new app in heroku, provisioned sendgrid following the steps from https://app.sendgrid.com/guide/integrate/langs/ruby, also added the missing line "sendgrid:starter" to app.json but still not sending any mail. Using the test script works fine: require 'sendgrid-ruby' include SendGrid from = Email.new(email: 'test@example.com') to = Email.new(email: 'test@example.com') subject = 'Sending with SendGrid is Fun' content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') mail = Mail.new(from, subject, to, content) sg = SendGrid::API.new(api_key: ENV['SENDGRID_APIKEY']) response = sg.client.mail.('send').post(request_body: mail.to_json) puts response.status_code puts response.body puts response.headers No errors in logs, actually it seems to work fine: Pwb::EnquiryMailer#general_enquiry_targeting_agency: processed outbound mail in 1504.8ms. Any other idea? Thank you.

etewiah commented 6 years ago

@cesarem, you need to set up sendgrid from within the heroku app. If this has been done correctly you will find that heroku automatically sets the SENDGRID_PASSWORD and SENDGRID_USERNAME config vars.
You can confirm this by going to the settings tab of your heroku dashboard and clicking the "Reveal Config Vars" button.

cesarem commented 6 years ago

Hi @etewiah, thanks for the post. Yeah, from the Heroku app works fine. Nevertheless, I'd need this to work from my VPS, and since I'm not yet a Rails developer, can you point which files should I modify in the src so I can integrate it with Sendgrid or another mailer? Thank you very much.

etewiah commented 6 years ago

Hi @cesarem , apologies for the delay in replying. If you don't use heroku, then you will need to configure actionmailer for whichever mail provider you choose. Each will have slightly different values to configure and most will provide some info for configuring Ruby on Rails. For Sendgrid for example, the details are here:

https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html