Google API发送带附件的电子邮件 - REST API致电Postman

发布于 2025-01-28 02:37:04 字数 1195 浏览 1 评论 0 原文

我想创建一个电子邮件/消息投掷Google API。 用户消息发送

我设法创建了一个简单的电子邮件(只有文本)使用此端点

POST https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/send

,并仅在身体中插入“原始”字段,其中包含此信息的基本64字符串,例如:

“

“


现在我正在尝试发送电子邮件一些附件,我无法正常工作。 我只找到了Java/JavaScript库的示例,但我想让它投掷标准REST API调用(现在我正在使用Postman来测试此端点)。

首先,我是否要使用 https:// https:// developers.google.com/gmail/api/reference/rest/v1/users.messages/send 或者 post

您可以留下带有正文文字和两个附件的电子邮件示例(例如两个PDF)吗? 谢谢

I want to create an email/message throw Google API. user messages send

I managed to create a simple email (only text) using this endPoint

POST https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/send

and inserting in the body only the "raw" field with the Base64 Encoded string that contains this info eg:

content of the base64 "raw" string

Postman Call


Now I'm trying to send an Email with some attachments and i can't get it to work.
I found only example with Java/Javascript libraries but I want to made it throw standard Rest Api Call (Now i'm using Postman to test this endpoints).

First of all , Have I to use https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send
OR
POST https://gmail.googleapis.com/upload/gmail/v1/users/{userId}/messages/send
?

Can you leave an example of an email with a body text and two attachments (for example two pdf) ?
Thank you

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

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

发布评论

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

评论(1

风蛊 2025-02-04 02:37:04

如果您使用的是邮递员,我建议您按照以下步骤进行操作:

1。)使用的端点是: https://gmail.googleapis.com/upload/gmail/gmail/gmail/v1/users/me/消息/发送?uploadType = multipart

2.)请求的内容类型标题应为: content-type:message/rfc822

3.)请求的正文应为:<代码> RAW-&GT;文本

4.)身体的内容应具有以下格式:

Content-Type: multipart/mixed; boundary=foo_bar_baz
MIME-Version: 1.0
to: [email protected]
from: [email protected]
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​​的方法...您可能需要检查它 - &gt; 邮件附件错误媒体类型Gmail Api

如果您有时间也想阅读此书 - &gt; https://wwwww.rfc-editor.org/rfc/rfc/rfc/rfc/rfc2046 。阅读它有助于我克服了我正在经历的困惑,并说明了上述步骤为何奏效。

If you are using postman, I suggest you to follow these steps to make it work:

1.) The endpoint to use is: https://gmail.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart

2.) The content type header of the request should be: Content-Type: message/rfc822

3.) The body of the request should be: raw -> text

4.) The content of the body should have the following format:

Content-Type: multipart/mixed; boundary=foo_bar_baz
MIME-Version: 1.0
to: [email protected]
from: [email protected]
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--

As a side note, I also followed the REST API documentation but I was getting all kind of error messages because I was confused. However, I found an old question that was able to help me to formulate the correct way of using the api... you might want to check it --> Mail attachment wrong media type Gmail API

If you have time, you might also want to read this --> https://www.rfc-editor.org/rfc/rfc2046. Reading it helped me overcome the confussion I was going through and gave me clarity as to why the above steps worked.

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