Delayed Jobs with Action Mailer using Mailjet API on a Heroku Rails App

518 views Asked by At

Looking to send a delayed jobs mailer with Mailjet's API, but the emails are not being sent. All works locally with Foreman, but again, on development on Heroku is not sending. The delayed jobs table was created.

Here's the gemfile

gem 'mailjet'

gem 'delayed_job_active_record'

The controller

def create
    @article = Article.new(article_params)

    if @article.save
    # send email to referral email
    all_users = User.all
    all_users.each do |user|
      ArticleMailer.delay.article_confirmation(user,@article)
   end 
   redirect_to @article
    else
     render 'new'
    end
end

The mailer

class ArticleMailer < ActionMailer::Base
  def article_confirmation(user,article)
    @user = user 
    @article = article 
    Mailjet::MessageDelivery.create(
      to: user.email,
      from: "[EMAIL]@gmail",
      subject:  "[HTML]",
      html: "[HTML]

  end

end

The /environments/development.rb file

 config.action_mailer.delivery_method = :mailjet

  config.action_mailer.smtp_settings = {
    address: "in-v3.mailjet.com",
    port: 587,
    domain: "[OURDOMAIN].com",
    authentication: "login",
    enable_starttls_auto: true,
    user_name: "[OUR_USERNAME]", 
    password: "[OUR_PASSWORD]",
    require_ssl: true 

}

The schema

  create_table "delayed_jobs", force: true do |t|
    t.integer  "priority",   default: 0, null: false
    t.integer  "attempts",   default: 0, null: false
    t.text     "handler",                null: false
    t.text     "last_error"
    t.datetime "run_at"
    t.datetime "locked_at"
    t.datetime "failed_at"
    t.string   "locked_by"
    t.string   "queue"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree

  create_table "friendly_id_slugs", force: true do |t|
    t.string   "slug",                      null: false
    t.integer  "sluggable_id",              null: false
    t.string   "sluggable_type", limit: 50
    t.string   "scope"
    t.datetime "created_at"
  end

UPDATE:

When I run Delayed::Job.last

=> #<Delayed::Backend::ActiveRecord::Job id: 181, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMailer\nobject...", last_error: nil, run_at: "2014-12-01 19:04:25", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2014-12-01 19:04:25", updated_at: "2014-12-01 19:04:25">
0

There are 0 answers