0

在 Heroku 上,我的自定义邮件不发送时,我根本没有收到任何错误。这是日志——

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

它在开发中工作得非常好 -

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

应用程序.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

从本地控制台尝试这些邮件命令可以正常工作,我在控制台中返回了电子邮件,但在 heroku 控制台中,它们返回一个 nil 对象 -

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

然而,这在 Heroku 控制台中工作正常?-

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

我快死了,我需要帮助!

4

0 回答 0