title: Using MailGun for ruby on rails application on Heroku
body: <p>I am trying to use MailGun to send emails in my RubyonRails application which is hosted on heroku.</p>
  
  <p>I added the MailGun addon to my heroku application. I updated my <code>config/environments/production.rb</code> as below:</p>
  
  <pre><code>config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :port           =&gt; ENV['MAILGUN_SMTP_PORT'],
      :address        =&gt; ENV['MAILGUN_SMTP_SERVER'],
      :user_name      =&gt; ENV['MAILGUN_SMTP_LOGIN'],
      :password       =&gt; ENV['MAILGUN_SMTP_PASSWORD'],
      :domain         =&gt; 'mydomain.herokuapp.com', #mydomain actually contains the realvalue
      :authentication =&gt; :plain,
    }
  </code></pre>
  
  <p>I created a file in app/mailers directory:</p>
  
  <pre><code>class ApplicationMailer &lt; ActionMailer::Base
    default from: "myemail@gmail.com"
  
    def notify_user(user)
      puts "Going to send email!! to"
      puts user
      mail(to: user, subject: "Welcome!")
    end
  end
  </code></pre>
  
  <p>In my application_controller.rb</p>
  
  <p>I have a function:</p>
  
  <pre><code>def notify_people()
      puts "Notify people!"
      ApplicationMailer.notify_user("xyz@gmail.com")
      puts "over"
  end
  </code></pre>
  
  <p>From one of my other controllers I call notify_people. However in my heroku logs, Notify people! is being printed, and nothing after that. I am not able to understand why it is not able to called notify_user.</p>
  
  <p>My notify_user function is:</p>
  
  <p>class ApplicationMailer &lt; ActionMailer::Base
    default from: "abcd@gmail.com"
    #layout 'mailer'
    def notify_user(user)
      puts "Going to send email!! to"
      puts user
      mail(to: user, subject: "Welcome!")
      puts "Done sending mail!"
      return
    end
  end</p>