Using MailGun for ruby on rails application on Heroku -
i trying use mailgun send emails in rubyonrails application hosted on heroku.
i added mailgun addon heroku application. updated config/environments/production.rb
below:
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :port => env['mailgun_smtp_port'], :address => env['mailgun_smtp_server'], :user_name => env['mailgun_smtp_login'], :password => env['mailgun_smtp_password'], :domain => 'mydomain.herokuapp.com', #mydomain contains realvalue :authentication => :plain, }
i created file in app/mailers directory:
class applicationmailer < actionmailer::base default from: "myemail@gmail.com" def notify_user(user) puts "going send email!! to" puts user mail(to: user, subject: "welcome!") end end
in application_controller.rb
i have function:
def notify_people() puts "notify people!" applicationmailer.notify_user("xyz@gmail.com") puts "over" end
from 1 of other controllers call notify_people. in heroku logs, notify people! being printed, , nothing after that. not able understand why not able called notify_user.
my notify_user function is:
class applicationmailer < actionmailer::base default from: "abcd@gmail.com" #layout 'mailer' def notify_user(user) puts "going send email!! to" puts user mail(to: user, subject: "welcome!") puts "done sending mail!" return end end
call mailer .deliver_later
:
applicationmailer.notify_user("xyz@gmail.com").deliver_later
also, make sure env variables set on heroku using details mailgun account.
edit: you're getting exception call applicationmailer
. ideally should troubleshoot in development, if needed can add: config.action_mailer.raise_delivery_errors = true
production.rb visibility what's happening.
tangentially, instead of print statements take @ debuggers byebug , pry-byebug. can save lot of time troubleshooting.
Comments
Post a Comment