亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Google Apps 腳本時使用查詢參數保護 URL

使用 Google Apps 腳本時使用查詢參數保護 URL

冉冉說 2023-02-17 10:24:14
我真的很難發送一封包含查詢參數的 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 = '[email protected]'    let creatorUsername = 'Sam'    template = template.replace(/[email protected]/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"))
查看完整描述

1 回答

?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

基于正則表達式的解決方案

在TanaikeRafa Guillermo的幫助下,最終為我工作的解決方案是用這樣的 小東西=代替:=.replace()listingUrl = listingUrl.replace(/=/, '=')


查看完整回答
反對 回復 2023-02-17
  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號