我真的很難發(fā)送一封包含查詢參數的 URL 的自動電子郵件(使用 Google Apps 腳本)。預期行為Google Apps 腳本(特別是Gmail服務)發(fā)送電子郵件,電子郵件正文的一部分包含帶有查詢參數的 URL。URL 看起來像這樣: http://my.app/products?id =Bz9n7PJLg8hufTj11gMF觀察到的行為該Gmail服務似乎正在從我的 URL 中刪除=。所以,電子郵件的正文最終看起來像這樣: ... http://my.app/products?idBz9n7PJLg8hufTj11gMF ...顯然,該鏈接將不起作用。我在這里檢查了其他關于 SO 的問題,并且嘗試使用GAS Utilities 服務中的基本編碼工具,以及使用encodeURI()JavaScript 方法。到目前為止沒有運氣。郵件發(fā)送代碼 //////// 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"))
使用 Google Apps 腳本時使用查詢參數保護 URL
冉冉說
2023-02-17 10:24:14