0

I'm tryong to send a email to all my application 's users.

In order to do that, i'm using whenever.

So I have a file /config/initializer/setup_mail.rb with my configuration smtp:

ActionMailer::Base.smtp_settings = {
    :tls => true,
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "miiaou.fr",
    :authentication => :plain,
    :user_name => "test.cicelle",
    :password => "myPasswordGoogle"
}

ActionMailer::Base.default_url_options[:host] = "miiaou.fr"

In my user.rb model:

def self.mail_recap_semaine
    @user = User.all
    @user.each do |u|
      UserMailer.mail_recap_semaine(u.email).deliver
    end
  end

In user_mailer.rb

def mail_recap_semaine(email)
    mail(:to => email, :subject => "Weekly email from footyaddicts")
  end

In schedule.rb (every 10 minutes, so I can see if it work)

every 10.minutes do
   runner "User.mail_recap_semaine"
end

when I run User.mail_recap_semaine in the rails console I got a lot of informations about my users but I do not receive any mail.

How could I see where is the bug? Thanks

cecile
  • 293
  • 1
  • 4
  • 17

2 Answers2

0

I order to debug what is the error or problem occurred while sending mail, you need to change the configuration settings of config/development.rb or config/production.rb to raise the errors for action mailer as like below.

config.action_mailer.raise_delivery_errors = true

By default, it is set to false, and hence you cannot get any errors.

Hope, it helps.

Thanks,

Mani

maniempire
  • 791
  • 11
  • 12
0

Ok, it was the :tls who break the code.

So now, my command in the rails console run perfectly and send email but the whenever still doesn't work.

crontab -l

# Begin Whenever generated tasks for: miiaou
0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /home/miiaou/miiaou && script/rails runner -e production '\''User.mail_recap_semaine'\'''

# End Whenever generated tasks for: miiaou

I have restart the server but I don't recieve anything.

cecile
  • 293
  • 1
  • 4
  • 17