0

When on Heroku my custom mailer does not send, I get no errors at all. This is the log -

Spree::HmsCommunicator#progress_email: processed outbound mail in 5.5ms
=> nil

It works perfectly fine in development -

Spree::HmsCommunicator#progress_email: processed outbound mail in 1178.4ms
Sent mail to blah@thehandbagspa.com (983.0ms)
Date: Tue, 19 Jan 2016 08:30:54 +0000
From: blah@thehandbagspa.com
To: blah@thehandbagspa.com
Message-ID: <569df43e70279_fe9a3ff1ae06020465535@Andrews-MacBook-Pro.local.mail>
Subject: Handbag Update | The Handbag Spa
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_569df43e6d9de_fe9a3ff1ae0602046541e";
 charset=UTF-8
Content-Transfer-Encoding: 7bit
track-opens: true

application.rb -

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :postmark
  config.action_mailer.perform_deliveries = true
  config.action_mailer.postmark_settings = { :api_token => "***...." }

hms_communicator.rb -

module Spree
  class HmsCommunicator < BaseMailer
    require 'twilio-ruby'
    def progress_email(handbag, stage, movedTo)
      @handbag = handbag
      @stage = stage
      @movedTo = movedTo
      mail(:subject => 'Handbag Update | The Handbag Spa',
           :to  => @handbag.user.email,
           :from => 'blah@thehandbagspa.com',
           :track_opens => 'true')
      #send_text_message
    end

    def test_email
      mail(:subject => 'Handbag Update | The Handbag Spa',
           :to  => 'blah@thehandbagspa.com',
           :from => 'blah@thehandbagspa.com',
           :body => 'hey',
           :track_opens => 'true')
    end

    def send_text_message
      account_sid = '****...'
      auth_token = '****...'
      alphanumeric_id = "TheHandbagS"
      twilio_phone_number = '+..'
      recipient_phone_number = '+..'

      client = Twilio::REST::Client.new(account_sid, auth_token)
      begin
        client.messages.create(
          from: alphanumeric_id,
          to:   recipient_phone_number,
          body: "Hello Freya. We have received your item into the spa. It will be enjoying it's first treatment shortly. Love, The Handbag Spa"
        )
      rescue Twilio::REST::RequestError => error
        if error.code == 21612
          client.messages.create(
            from: twilio_phone_number,
            to:   recipient_phone_number,
            body: "Hello, this is a message from Andrew"
          )
        else
          # handle this some other way
          raise error
        end
      end
    end


  end
end

Trying these mail commands from the console locally works fine and I get the email returned in the console but in heroku console they return a nil object -

Spree::HmsCommunicator#progress_email: processed outbound mail in 5.0ms => #<ActionMailer::Base::NullMail:0x007fc9cc5c19b0>

However this works fine in the Heroku console?? -

ActionMailer::Base.mail(from: "test@example.co", to: "valid.recipient@domain.com", subject: "Test", body: "Test").deliver_now

I'm dying here, I need some help!

AndrewJL
  • 118
  • 2
  • 10
  • Are you calling `deliver_later` or `deliver_now` to send your message? – taglia Jan 19 '16 at 09:05
  • Tried `deliver` and `deliver_now`, `deliver_later` gives this - `Spree::HmsCommunicator#progress_email: processed outbound mail in 9.8ms [ActiveJob] [ActionMailer::DeliveryJob] [aca6d0a5-0f1c-43c8-91b5-331d1bbafd14] Spree::HmsCommunicator#progress_email: processed outbound mail in 9.8ms Performed ActionMailer::DeliveryJob from Inline(mailers) in 12.52ms [ActiveJob] [ActionMailer::DeliveryJob] [aca6d0a5-0f1c-43c8-91b5-331d1bbafd14] Performed ActionMailer::DeliveryJob from Inline(mailers) in 12.52ms`. Thanks. – AndrewJL Jan 19 '16 at 09:08
  • If you tried `deliver_now` it means it's not an ActiveJob issue. I'm sorry I'm not able to help more, I have never played with postmark. You might want to check in `production.rb` if by any chance you are overriding any `action_mailer` setting, which would explain why it works in dev and not in prod. – taglia Jan 19 '16 at 09:12
  • Ok thanks for your help. I tried replacing `production.rb` with `development.rb` to no avail. This ones a toughy :( – AndrewJL Jan 19 '16 at 09:18
  • 1
    There might not be an issue with your code. Postmark will silently fail if you haven't whitelisted your [sender signature](https://postmarkapp.com/signatures). Is that all set up correctly? Can you manually send an email via their API with cURL? – Dylan Moore Jan 19 '16 at 22:20
  • Thanks Dylan. Yeah it's all set up correctly. It sends locally which is the oddest thing. I have found that when I try the custom mail command from the console without .deliver_now I get more of an output - `Spree::HmsCommunicator#progress_email: processed outbound mail in 5.0ms => #` I have no idea why it's returning this Null object. This works fine from heroku - `ActionMailer::Base.mail(from: "test@example.co", to: "valid.recipient@domain.com", subject: "Test", body: "Test").deliver`. I have added my custom mailer to the question. – AndrewJL Jan 20 '16 at 10:54
  • *groan*. would be cool if it didn't silently fail :/ – Damien Roche Dec 11 '18 at 12:35

0 Answers0