微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – Rails cron不发送电子邮件

我正在使用随时随地拥有rails cron作业发送电子邮件.一切似乎工作得很好,我的cron.log或我的production.log文件没有错误,但我从来没有收到过电子邮件.我已经检查过电子邮件地址也是正确的.

任何帮助表示赞赏.

production.log文件包含以下内容

Connecting to database specified by database.yml
  Rendered email_mailer/send_birthday_reminders.html.erb (5.3ms)

Sent mail to tomcaflisch@gmail.com (409ms)

这是我的每当gem schedule.rb文件

set :output,"#{path}/log/cron.log"

every :hour do
    runner "BirthdayRemindersController.send_birthday_email_reminders"
end

birthday_reminders_controller.rb

class BirthdayRemindersController < ApplicationController

    # cron job that sends birthday reminders
    def self.send_birthday_email_reminders 
        users = User.all

        email_addresses = []

        users.each_with_index do |user,i|
            if user.user_details.birthday_reminders == true
                email_addresses[i] = get_primary_email(user)
            end
        end
        p "email_addresses to send to:"
        p email_addresses

        users.each do |user|
            p "this user is"
            p user.user_details.full_name
            if user.user_details.birthday.try(:strftime,"%m") == Date.today.strftime("%m") && user.user_details.birthday.try(:strftime,"%d") == Date.today.strftime("%d")
                p "reminder sent"
                EmailMailer.send_birthday_reminders(user,email_addresses).deliver
            end
        end
    end
end

email_mailer.rb片段

class EmailMailer < ActionMailer::Base
  include ApplicationHelper
  default :from => "\"FamNFo\" <no-reply@mysite.com>"

  def send_birthday_reminders(birthday_person,email_addresses)
    p "we in send_birthday_reminders mailer"
    p email_addresses
    @birthday_person = birthday_person
    mail(:subject => "Birthday Reminder For The Caflisch Family",:to => email_addresses,:reply_to => email_addresses)
  end
end

capistrano的deploy.rb包含了这个

# needed for the 'whenever' gem
set(:whenever_command) { "RAILS_ENV=#{rails_env} bundle exec whenever"}
require "whenever/capistrano"

解决方法

检查垃圾邮件文件夹.要确保电子邮件不会在那里结束,请在每封电子邮件添加“取消订阅链接.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐