Sendgrid configured on Rails 4

I have an application for rails 4. I created ActionMailer and I can send order confirmation emails through localhost and gmail.

I installed Sendgrid on Heroku and followed the setup instructions. I get Net::SMTPSyntaxError (501 Syntax error

my environment.rb (I have sendgrid user / pwd in application.yml)

 ActionMailer::Base.smtp_settings = { :address => 'smtp.sendgrid.net', :port => '587', :authentication => :plain, :user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], :domain => 'heroku.com', :enable_starttls_auto => true } 

in production.rb is the only actionamailer parameter that I have. I have this as a placeholder to post a real domain later. I am currently using herokuapp.com.

 config.action_mailer.default_url_options = { host: 'localhost:3000' } 

in my order_controller in the order creation method, I call below.

 AutoNotifier.orderconf_email(current_user, @order).deliver 

auto_notifier.rb

 class AutoNotifier < ActionMailer::Base default from: "Test Email" def orderconf_email(current_user, order) @buyer = current_user @order = order mail(to: @buyer.email, subject: 'Thank you for your order.') end end 

What am I missing? It works on localhost with gmail, so I'm missing something in the sendgrid settings or in the default_url file in the production.rb file.

+6
source share
3 answers

Change default from: "Test Email" to a valid email address, even example@example.com .

+4
source

For posterity, a working setting has been created for external SMTP in Rails on Heroku:

 #config/environments/production.rb config.action_mailer.smtp_settings = { :address => "smtp.sendgrid.net", :port => 587, # ports 587 and 2525 are also supported with STARTTLS :enable_starttls_auto => true, # detects and uses STARTTLS :user_name => ENV["SENDGRID_USERNAME"], :password => ENV["SENDGRID_PASSWORD"], # SMTP password is any valid API key, when user_name is "apikey". :authentication => 'login', :domain => 'yourdomain.com', # your domain to identify your server when connecting } 
+23
source

I would like to note that this is for sending emails via SMTP. Although this method is completely suitable, you should also consider sending via the API.

For this you need to specify an interceptor. Fortunately, there is a gem that helps with this. Here's a good article showing how to use it.

https://rubyplus.com/articles/561-Sending-Emails-using-SendGrid-API-in-Rails-4-1

0
source

Source: https://habr.com/ru/post/974847/


All Articles