我想通过 Google API 创建电子邮件/消息。用户消息发送 https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send
我设法使用此端点创建了一封简单的电子邮件(仅文本)
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/send
并仅在正文中插入包含此信息的 Base64 编码字符串的“原始”字段,例如:
现在我正在尝试发送一封带有一些附件的电子邮件,但无法正常工作。
我只找到了 Java/Javascript 库的示例,但我想让它抛出标准的 Rest Api 调用(现在我正在使用 Postman 来测试这个端点)。
首先,我要使用https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send或者
邮政https://gmail.googleapis.com/upload/gmail/v1/users/{userId}/messages/send https://gmail.googleapis.com/upload/gmail/v1/users/%7BuserId%7D/messages/send
?
您能否留下包含正文和两个附件(例如两个 pdf)的电子邮件示例?
谢谢
如果您使用邮递员,我建议您按照以下步骤使其正常工作:
1.) 要使用的端点是:https://gmail.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart
2.) 请求的内容类型标头应为:Content-Type: message/rfc822
3.) 请求正文应为:raw -> text
4.) 正文内容应采用以下格式:
Content-Type: multipart/mixed; boundary=foo_bar_baz
MIME-Version: 1.0
to: [email protected] /cdn-cgi/l/email-protection
from: [email protected] /cdn-cgi/l/email-protection
subject: POSTMAN Rest API Execution
--foo_bar_baz
Content-Type: text/html; charset="UTF-8"
MIME-Version: 1.0
<h1>What is Lorem Ipsum?</h1>
<p style="color: darkred">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum<p>
--foo_bar_baz
Content-Type: application/pdf
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Attachment_file.pdf"
JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoUHJvamVjdCBwcm9wb3NhbCkKL1Byb2R1Y2VyIChTa2lhL1BERiBtMTAzIEdvb2dsZSBEb2NzIFJlbmRlcmVyKT4+CmVuZG9iagozIDAgb2JqCjw8L2NhIDEKL0JNIC9Ob3JtYWw+PgplbmRvYmoKNyAwIG9iago8PC9UeXBlIC9YT2JqZWN0Ci9TdWJ0eXBlIC9JbWFnZQovV2lkdGggMTIwMAovSGVpZ2h0IDEyCi9Db2xvclNwYWNlIC9EZXZpY2VSR0IKL0JpdHNQZXJDb21wb25lbnQ==
--foo_bar_baz--
附带说明一下,我还遵循了 REST API 文档,但我收到了各种错误消息,因为我很困惑。然而,我发现了一个老问题,它能够帮助我制定使用 api 的正确方法...你可能想检查一下 -->邮件附件媒体类型错误 Gmail API https://stackoverflow.com/questions/24908700/mail-attachment-wrong-media-type-gmail-api
如果你有时间,你可能还想读一下这个 -->https://www.rfc-editor.org/rfc/rfc2046 https://www.rfc-editor.org/rfc/rfc2046。阅读它帮助我克服了我所经历的困惑,并让我清楚了为什么上述步骤有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)