SendGrid
Configure SendGrid for production.
Used 56 times
S
Steve Polito
Usage
Configures SendGrid for production.
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/x7msBK"
Template Source
Review the code before running this template on your machine.
domain_name = ask('What is your domain name?')
def do_bundle
# Custom bundle command ensures dependencies are correctly installed
Bundler.with_unbundled_env { run 'bundle install' }
end
run 'bundle add sendgrid-ruby'
do_bundle
inject_into_file 'config/environments/production.rb', after: "Rails.application.configure do\n" do <<~EOF
config.action_mailer.default_url_options = {host: "#{domain_name}"}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => "#{domain_name}",
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
EOF
end