如何在 Google App Engine 邮件 API 中添加自定义电子邮件 headers

How to add custom email headers in Google App Engine Mail API

我需要有关如何在使用 GAE 的邮件 API (Python) 发送电子邮件时添加多个自定义电子邮件 headers 的帮助,即 Message-id、person-id等等

但不知何故,我没有在文档中看到它:https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.mail

我可以使用以下方法接收电子邮件和阅读自定义电子邮件 headers: mail_message.original.getitem('mail_header')

但我不知道如何使用自定义电子邮件发送电子邮件 headers。

这是我用来发送电子邮件的代码:

mail.send_mail(sender=sender_address,
               to="handsome_me@yahoo.com",
               subject="gwapo",
               body="Hi")

看起来您错过了文档中的这一行:

PROPERTIES = set(['body', 'amp_html', 'sender', 'to', 'cc', 'bcc', 'attachments', 'headers', 'html', 'reply_to', 'subject'])

您可以提供一个 headers 参数,其中包含自定义列表 headers。

查看来源,headers 参数受以下限制:

  • 必须是字典
  • 所有值必须是字符串
  • 所有键必须是 ASCII
  • 密钥应在以下白名单中:Auto-SubmittedIn-Reply-ToList-IdList-UnsubscribeOn-Behalf-OfReferencesResent-Date, Resent-From, Resent-To.

恐怕您无法使用 AppEngine 覆盖 message-id,因为它不在 HEADERS_WHITELIST 中。我忘了 AppEngine 有多残废,你可能想检查一下 third-party email services. I've used mailgun and they allow arbitrary headers as long as they are prefixed by X- (just include a h:X-My-Arbitrary-Header in the payload). From the AppEngine docs:

Sending Messages with Third-Party Services

Python 2.7/3.7 |Java 8/11 |PHP 5/7 |Ruby |Go 1.9/1.11/1.12 |Node.js Python 3.7 applications on App Engine can use third-party companies to send email, SMS messages, or make and receive phone calls. For example, you might send email to confirm business transactions, confirm the creation of user accounts, or send marketing communications.

This page lists some examples of companies that provide communication services and client libraries for Python 3.7 applications on App Engine.

Note: The services offered by these third-party companies are not covered by the App Engine Service Level Agreement.

Mailgun

Mailgun provides both RESTful APIs and client libraries for sending email. As a GCP project user, your first 30,000 messages are free every month. See the monthly pricing calculator on the sign up page for pricing on additional messages and volume discounts.

Learn more about Mailgun:

...

SendGrid

You can use SendGrid to power your emails on App Engine. SendGrid can improve your deliverability and provide transparency into what actually happens to those emails your app sends. You can see statistics on opens, clicks, unsubscribes, spam reports and more with the SendGrid interface or its API.

App Engine customers can send 12,000 emails every month for free by signing up for the SendGrid Email API plan through the Google Cloud Platform Console. Note that Google is compensated for customers who sign up for a paid account.

Learn more about SendGrid:

我不隶属于其中任何一个,原始页面提到了其他服务,我引用了 mailgun 是因为我用过它并且知道它有效,而 sendgrid 是因为 OP 提到了它。

我正在开发 devselz.com 一项允许每月发送无限量电子邮件的服务。它使用带有私人服务器的 P2P,用户可以在其中使用自己的服务器(通过安装 devselz 提供的 compatct SMTP。)

这是文档:https://devselz.com/support/