lundi 25 mai 2015

Sent emails with Action Mailer

I am trying to send an email to example@gmail.com with Action Mailer (Ruby on Rails). The method sendactivation is correctly executed and the message "Email sent" is displayed. However, I never receive any email. Actually, the output "Test" is never printed. My webapp is hosted on Heroku Cedar-10.

class UsersController < ApplicationController
  def sendactivation
      UserMailer.welcome_email()
      render :json => {
        :result => "Email sent"
      }
    end
  end
end

class UserMailer < ActionMailer::Base
  def welcome_email()
    mail(to: "example@gmail.com",
         body: "Hello",
         content_type: "text/html",
         subject: "Already rendered!")
    puts "Test"
  end
end

This is the configuration I have on my config/environment/production.rb. Actually I wanted to send it with Office 365 but I suppose it is easier to debug with a Gmail account.

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    user_name:            'example@gmail.com',
    password:             '########',
    authentication:       'plain',
    enable_starttls_auto: true  }

What am I doing wrong? Is there anything I need to change on my Gmail configuration?

Aucun commentaire:

Enregistrer un commentaire