gpt4 book ai didi

email - 使用Google Script在Gmail中插入带有超链接的文本吗?

转载 作者:行者123 更新时间:2023-12-04 23:16:18 24 4
gpt4 key购买 nike

我正在尝试发送带有附件和附件URL的电子邮件。电子邮件正文如下所示:

“大家好-

这是明天 session 的agenda

早上见!

-约翰·多伊(John Doe)

我已经尽我最大的能力编写了代码。我知道我错误地写了下半部分。请协助。

  function sendEmailTest() {
//test send email.
// Send an email with an attachment: a file from Google Drive.
var file = DocumentApp.openById(file2.getId());
var ssUrl = 'URL_BUFFERED';
var sheetName = 'Sheet1'; // name of sheet to use
var rangeName = 'C30'; // range of values to include
var dateRange = SpreadsheetApp.openByUrl(ssUrl)
.getSheetByName(sheetName)
.getRange(rangeName)
.getValues();

// Name of Google file to attach.
var file2 = file.makeCopy('Weekly Agenda | '+dateRange);

// Set Agenda URL.
var theBody = GmailApp.openById(file2.getId()).getBody();
var elementReplaced = theBody.replaceText("%toReplace%", "agendaURL");
elementReplaced.asText().setLinkUrl("https://google.com");

//Send email.
MailApp.sendEmail('who@whowantstoknow.com', file2, 'Hi Everyone- \n Here\'s the ' +agendaURL+'agenda for tomorrow
's meeting. \n See you in the morning! \n-John Doe', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(file2)] });
}

最佳答案

在电子邮件中插入超链接需要以HTML发送电子邮件,而不是像现在那样以纯文本发送电子邮件。将sendEmail调用的语法更改为 sendEmail(Object) ,其中参数是带有包含您的消息的htmlBody字段的对象。像这样:

var message = {
to: "recipient@example.com",
subject: "Weekly Agenda | " + dateRange,
htmlBody: "Hi Everyone-\n Here's the <a href='" + agendaURL + ''">agenda</a> for tomorrow's meeting.\n See you in the morning!\n-John Doe",
name: "Automatic Emailer Script",
attachments: [file2.getAs(MimeType.PDF)]
};
MailApp.sendEmail(message);

最好在消息正文中使用双引号,因为这样您就不必在文本中转义撇号了。

关于email - 使用Google Script在Gmail中插入带有超链接的文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41112629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com