Search code examples
ruby-on-railsherokusendgrid

Sendgrid set up on Rails 4


I have a rails 4 app. I set up ActionMailer and I can send order confirmation emails via localhost and gmail.

I installed Sendgrid on Heroku and followed the set up instructions. I get a 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 - the only actionamailer setting i have is this. I have this as a placeholder to put the real domain in later. I'm currently using herokuapp.com.

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

in my orders_controller within the order create method, I call the 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 in production.rb file.


Solution

  • Change default from: "Test Email" to valid email address, even [email protected].