I'm having some trouble sending email using ActionMailer with Gmail. I've attempted to use Mandrill but it's still not sending. When testing ActionMailer with gmail it works in development only but in production there seems to be an issue.
I've tried multiple solutions but nothing seems to be working. I've tried setting up action mailer settings in environment.rb, swapped from gmail to mandrill. I can't seem to figure out what I'm missing.
Let me know what you think. I've provided the code snippets below
production.rb:
config.action_mailer.default_url_options = { :host => ENV["HEROKU_DOMAIN"] }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.mandrillapp.com",
port: 587,
domain: ENV["HEROKU_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["HEROKU_USERNAME"],
password: ENV["MANDRILL_KEY"]
}
email_signup.rb:
class EmailSignup < ApplicationMailer
default from: "[email protected]"
def sample_email(user)
@user = user
mail subject: "test", to: user.email
end
end
users_controller.rb:
def create
@user = User.new(user_params)
if @user.save
@user.save
EmailSignup.sample_email(@user).deliver
redirect_to thanks_path
else
redirect_to root_path
end
end
Neo's solution solved my problem.
All I did was set the environment variables on Heroku.
and all the other variables and that fixed it.