Note: This article supersedes our now legacy SendGrid Add-on and should be used as the method to integrate SendGrid into your application. This method applies to our stable-v5 stack and higher, if you are on a lower stack version than this please contact our Support team.
SendGrid can easily be integrated into your applications by obtaining SG sending credentials and setting these as Environment Variables via the EY Cloud dashboard, then sourcing these in your application's configuration.
Part 1: SendGrid
- Head to https://app.sendgrid.com/login and create a new account if you do not have one yet. If you do, log in
- Once in your account click on Settings > API Keys
- Click Create Key and enter a name for your API key, ideally related to the application & environment it will be used on for ease of future reference
- Once you have your key, copy it and make sure you have it saved for a later point. Important: keys cannot be viewed again after this point
Part 2: EY Cloud
- Modify your
config/environments/production.rb
by adding the following: (Make sure to replace"yourdomain.com"
with the domain you will be sending the email from, all other values should be left as-is).config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.smtp_settings = { :authentication => :plain, :address => "smtp.sendgrid.net", :port => 587, :domain => "yourdomain.com", :user_name => "apikey", :password => ENV['SENDGRID_API_KEY'], :authentication => 'plain', :enable_starttls_auto => true }
- Push the changes to your code onto the repo where it is hosted
- Add your API key from Step 4 of Part 1 to the Environment Variables for your environment, calling it
SENDGRID_API_KEY
. The Environment Variables page is linked from under More Options on the Environment page of the EY dashboard - Apply the changes to your environment so that environment variable are pushed to the instances and the key is accessible by your app
- Deploy your application
There is an error in this configuration that took us hours to debug!! instead of
:api_key => ENV['SENDGRID_API_KEY']
It should be
:password => ENV['SENDGRID_API_KEY'],
See the docs on Sendgrid's website:
https://docs.sendgrid.com/for-developers/sending-email/rubyonrails
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey', # This is the string literal 'apikey', NOT the ID of your API key
:password => '', # This is the secret sendgrid API key which was issued during API key creation
:domain => 'yourdomain.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Hi Benjamin,
Thank you for your comment, and we're sorry for the inconvenience that you've faced. Please feel free to use our support team, by filing a support ticket, when facing an issue related to the platform and Add-Ons in the future. Our 24/7 Support team will be more than happy to assist with matters such as these.
The article has now been updated.
Best,
Gideon