[英]How can I supply email headers sending in Google MailApp?
How can I include email headers information using Google MailApp api?如何使用 Google MailApp api 包含 email 标头信息?
I need to supply headers info such as List-Unsubscribe:
or List-Unsubscribe-Post:
.我需要提供标头信息,例如
List-Unsubscribe:
或List-Unsubscribe-Post:
。
The following is a code sample by Google Apps Script.以下是 Google Apps Script 的代码示例。 It seems that there is no option to include such email header info.
似乎没有选择包含这样的 email header 信息。
sendEmail(recipient, subject, body, options)
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html',
'my_document.html');
MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
I believe your goal as follows.我相信你的目标如下。
List-Unsubscribe
and List-Unsubscribe-Post
to the Gmail and send it using Google Apps Script.List-Unsubscribe
和List-Unsubscribe-Post
的自定义标头添加到 Gmail 并使用 Google Apps 脚本发送。 In this case, how about the following flow?在这种情况下,下面的流程怎么样?
MailApp.sendEmail
in your script are used.MailApp.sendEmail
的 arguments。 When this flow is reflected to your script, it becomes as follows.当这个流程反映到您的脚本时,它变成如下。
Before you use this script, please enable Gmail API at Advanced Google services .在使用此脚本之前, 请在 Google 高级服务中启用 Gmail API 。
var obj = {"List-Unsubscribe": "sample1", "List-Unsubscribe-Post": "sample2"}; // Please set the custom headers.
// 1. Create a draft as a temporal.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
var draft = GmailApp.createDraft('mike@example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
// 2. Add the custom headers.
var data = Object.entries(obj).map(([k, v]) => `${k}: ${v}`).join("\n") + "\n" + draft.getMessage().getRawContent();
// 3. Delete Draft.
draft.deleteDraft();
// 4. Send the draft using Gmail API.
var res = Gmail.Users.Messages.send({raw: Utilities.base64EncodeWebSafe(data)}, "me");
console.log(res)
List-Unsubscribe: sample1
and List-Unsubscribe-Post: sample2
are used as the sample values.List-Unsubscribe: sample1
和List-Unsubscribe-Post: sample2
用作示例值。 Please modify this for your actual situation.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.