我真的很难发送一封包含查询参数的 URL 的自动电子邮件(使用 Google Apps 脚本)。
Google Apps 脚本(特别是Gmail
服务)发送电子邮件,电子邮件正文的一部分包含带有查询参数的 URL。URL 看起来像这样: http://my.app/products?id =Bz9n7PJLg8hufTj11gMF
该Gmail
服务似乎正在从我的 URL 中删除=
。所以,电子邮件的正文最终看起来像这样: ... http://my.app/products?idBz9n7PJLg8hufTj11gMF ...
显然,该链接将不起作用。
我在这里检查了其他关于 SO 的问题,并且尝试使用GAS Utilities 服务中的基本编码工具,以及使用encodeURI()
JavaScript 方法。到目前为止没有运气。
//////// GENERATING MESSAGE FROM ID ////////////
// Gets message from ID
var id = Gmail.Users.Drafts.get('me', 'r-1006091711303067868').message.id
var message = GmailApp.getMessageById(id)
var template = message.getRawContent()
// Replaces template variables with custom ones for the user using RegExes
let listingUrl = 'http://my.app/products?id=xyz'
let creatorEmail = 'hello@gmail.com'
let creatorUsername = 'Sam'
template = template.replace(/templates@my.app/g, creatorEmail)
template = template.replace(/firstName/g, creatorUsername)
//** Below is the string that gets modified and broken **//
template = template.replace(/listingUrl/g, listingUrl)
// Creates the new message
var message = Gmail.newMessage()
var encodedMsg = Utilities.base64EncodeWebSafe(template)
message.raw = encodedMsg
// Sends it
Gmail.Users.Messages.send(message, "me", Utilities.newBlob(template, "message/rfc822"))
三国纷争
相关分类