Question

when I try to send an email via sendgrid on heroku cedar stack, I got an following error :

ArgumentError (SMTP-AUTH requested but missing user name):

my settings in /environments/staging.rb are :

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'myapp' }

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

My Sendgrid password/username are obtained from Heroku according to this page

Does anyone have any suggestion ?

Was it helpful?

Solution

Try moving your config from config/enviornments/staging.rb into config/initializers/smtp.rb. That way you know ActionMailer is configured regardless of the environment you're in.

You should keep delivery specific setting in your environment files:

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top