如何找到ActionMailer发送的Sendgrid电子邮件的有效载荷?

时间:2019-06-20 15:13:14

标签: ruby-on-rails ruby actionmailer sendgrid payload

我正在与SendGrid支持一起确定为什么类别在我的多部分电子邮件广告系列中停止工作(纯文本格式是可以的)。如果我有意将HTML电子邮件的内容类型设置为“文本/纯文本”,则该电子邮件会在单个电子邮件上显示标头数据,文本和原始html,但会得到其类别。否则,电子邮件看上去正确,但是没有类别。

SendGrid已要求我向他们发送有效载荷的副本,但我不确定这是什么或如何找到它。他们说:“如果您熟悉运行telnet测试,那么这就是我们想要的。”我不熟悉telnet测试。这是他们提供的屏幕快照中的信息,作为他们正在寻找的示例:

220 Hi! This is Rob's hMailServer!
ehlo panoply-tech.com
250-SAGE013963
250-SIZE 20480000
250 AUTH LOGIN PLAIN
AUTH LOGIN
334 VXN1ea5bbVUG
YT3TQBHbhM9WBHKTDGUjeD65WQ20=
235 authenticated.
MAIL FROM: mayes@panoply-tech.com
250 OK
RCPT TO: cstickings@demosagecrm.com
250 OK
DATA
354 OK, send.
Subject: This is a test email
Hi Clemence,
Just sending you a test email.
.
250 Queued <25.927 seconds>

我去了.rvm / gems / ruby​​-2.3.3 / gems / actionmailer-4.2.8 / lib / action_mailer / base.rb,发现了一个名为“ set_payload_for_mail”的方法,但是产生的结果确实像他们例如:

{"mailer":"B2c::B2cSendGridMailer",
"message_id":"5d0b979767c26_16f2c3fc04043f9c84968e@Domain-Person.local.mail",
"subject":"TEST: 26_txt","to":["person@domain.com"],
"from":["info@another.com"],"date":"2019-06-20T09:26:31.000-05:00",
"mail":"Date: Thu, 20 Jun 2019 09:26:31 -0500\r\nFrom: info@another.com\r\nTo: person@domain.com\r\nMessage-ID: \u003c5d0b979767c26_16f2c3fc04043f9c84968e@Domain-Person.local.mail\u003e\r\nSubject: TEST: 26_txt\r\nMime-Version: 1.0\r\nContent-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\n
X-SMTPAPI: {\"category\":[\"html_false\"]}\r\n
X-SMTPAPI: {\"filters\": {\"ganalytics\": {\"settings\": {\"enable\":1}}}}
\r\n\r\nHi there, but text\r\n"}

我知道在Google收件箱中,您可以单击“显示原始邮件”以查看电子邮件,并查看标头信息等。我已将其发送给他们,但没有他们需要的信息。

  def b2c_tester(html=false, content)
        e_domain = 'careinhomes.com'
        @mailer_path = "app/views/b2c/b2c_send_grid_mailer"
        @from = "info@careinhomes.com"
        @recipients = ['gina@pipelinesuccess.com']
        @subject = html ? "#{DateTime.now.minute.to_s}_html" : 
              "#{DateTime.now.minute.to_s}_txt"

        header_category = {"category": ["html_#{html}"]}
        headers['X-SMTPAPI'] = header_category.to_json

        if html
          msg = tester_mail_with_opts({domain: e_domain}, content)
        else
          msg = tester_mail_plain_text_with_opts(
              "b2c_tester",{domain: e_domain})
        end
        msg
    end

   #content ex: 'text/plain', 'text/html', 'multipart/alternative', etc
    def tester_mail_with_opts(delivery_options={}, content=nil)
      mail_opts = set_mail_opts(delivery_options)
      unless content.nil?
        mail_opts[:content_type] = content
      end
      mail mail_opts
    end

  def set_mail_opts(delivery_options={})
      @subject = "TEST: #{@subject}" unless Rails.env.production?
      # Required
      mail_opts = {
          to: @recipients,
          from: @from,
          subject: @subject,
      }

      mail_opts[:template_path] = @template_path if @template_path
      mail_opts[:content_type] = @content_type if @content_type

      # Do delivery options
      mail_opts[:delivery_method_options] = DELIVERY_OPTIONS
      mail_opts[:delivery_method_options] = 
        mail_opts[:delivery_method_options].merge(delivery_options) 
              unless delivery_options.blank?
      mail_opts
    end

1 个答案:

答案 0 :(得分:0)

在ActionMailer的基本模型中,有一种称为delivery_mail的方法,该方法提取有效负载,您可以用这种方式捕获它。对于我的问题,有效负载似乎是一个空哈希。

这是从ActionMailer中获得的有效负载的样子:

{"mailer":"B2c::B2cSendGridMailer","message_id":"5d10dacb26dc2_17fb93ff52483b9c8952bf@Domain-Person.local.mail","subject":"TEST: 14_txt","to":["person@domain.com"],"from":["info@another.com"],"date":"2019-06-24T09:14:35.000-05:00","mail":"Date: Mon, 24 Jun 2019 09:14:35 -0500\r\nFrom: info@another.com\r\nTo: person@domain.com\r\nMessage-ID: \u003c5d10dacb26dc2_17fb93ff52483b9c8952bf@Domain-Person.local.mail\u003e\r\nSubject: TEST: 14_txt\r\nMime-Version: 1.0\r\nContent-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\nX-SMTPAPI: {\"category\":[\"html_false\"]}\r\nX-SMTPAPI: {\"filters\": {\"ganalytics\": {\"settings\": {\"enable\":1}}}}\r\n\r\nHi there, but text\r\n"}