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. >_<
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With