Ruby 自定义电子邮件标头

发布于 2024-12-21 01:45:37 字数 401 浏览 5 评论 0原文

我正在尝试发送一封带有自定义标头的电子邮件,但由于某种原因,他们无法发送。

当我在控制台中调用邮件方法时,实际上列出了我的自定义参数:

<X-SMTPAPI: {"messageid" : "nomnom"}>

这就是我在代码中所做的事情:

headers["X-SMTPAPI"] = "{\"messageid\" : \"nomnom\"}"
mail(:to => @user.email, :subject => "Confirmation"  )

知道我做错了什么吗?

编辑: 问题似乎在于使用 X-SMTPAPI 作为密钥。使用其他东西确实有效。

I'm trying to send an email with custom headers but for some reason they just don't get through.

When I call my mailing method in the console, my custom parameter is actually listed:

<X-SMTPAPI: {"messageid" : "nomnom"}>

This is what I'm doing in my code:

headers["X-SMTPAPI"] = "{\"messageid\" : \"nomnom\"}"
mail(:to => @user.email, :subject => "Confirmation"  )

Any idea what I'm doing wrong?

EDIT:
The problem seems to be with using X-SMTPAPIas key. Using something else does work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小墨 2024-12-28 01:45:37

指定标头的语法如下:

headers({'X-No-Spam' => 'True', 'In-Reply-To' => '[email protected]'})

查看ActionMailer::Base 文档

The syntax for specifying headers is as follows:

headers({'X-No-Spam' => 'True', 'In-Reply-To' => '[email protected]'})

Looked at ActionMailer::Base documentation.

梦里人 2024-12-28 01:45:37

标头只能设置为完全有效的 JSON。这应该有效:

headers['X-SMTPAPI'] = '{"thing": "SomeEmail"}'

The Headers can only be set to perfectly valid JSON. This should work:

headers['X-SMTPAPI'] = '{"thing": "SomeEmail"}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文