【发布时间】:2019-06-20 15:13:14
【问题描述】:
我正在使用 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
【问题讨论】:
标签: ruby-on-rails ruby actionmailer sendgrid payload