Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to debug mailer with sendgrid on heroku? Or to check if the mail get actually sent?

I'm trying to implement a "contact us" form on my rails 3.0.10 project. Following the RailsGuides I created a mailer.

class QuestionMailer < ActionMailer::Base
  default :to => "%mail@mydomain" #gmail for domains

  def ask(message)
    @content = message.content

    unless message.name.nil? or message.name.empty?
      from = "#{message.name} <#{message.email}>"
    else
      from = message.email
    end

    mail(:subject => message.subject, :from => from)
  end
end

In my controller I have these lines:

if @question.valid?
  QuestionMailer.ask(@question).deliver
  redirect_to root_url, :notice => "Сообщение отправлено"
else

Production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '%mydomain%' }

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

I didn't have this config at first, but when I didn't receive the email, I added it.

The problem is, the Heroku log says, that the corresponding view has been rendered, but I don't receive the email. And because I use sendgrid, I cant test it locally.

upd

Note to self. After creating gmail for domain account, don't forget to your DNS settings. >_<

like image 525
bassneck Avatar asked Aug 24 '11 07:08

bassneck


1 Answers

You can test locally still using sendgrid - from the command line do heroku config and you can grab the values that Heroku has set for sendgrid username, password and domain and then set them in your development.rb along with the actionmailer settings and it will route your message through sendgrid from your local development app.

I also find this heroku plugin https://github.com/hone/heroku-sendgrid-stats very useful for checking on my message sending numbers.

like image 174
John Beynon Avatar answered Oct 11 '22 14:10

John Beynon