Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Google Apps脚本时使用查询参数保护URL_Javascript_Google Apps Script_Gmail_Gmail Api_Urlencode - Fatal编程技术网

Javascript 使用Google Apps脚本时使用查询参数保护URL

Javascript 使用Google Apps脚本时使用查询参数保护URL,javascript,google-apps-script,gmail,gmail-api,urlencode,Javascript,Google Apps Script,Gmail,Gmail Api,Urlencode,我真的很难发送一封自动电子邮件(使用谷歌应用程序脚本),其中包含一个包含查询参数的URL 预期行为 谷歌应用程序脚本(特别是Gmail服务)发送一封电子邮件,电子邮件正文的一部分包含一个带有查询参数的URL。URL将如下所示: 观察到的行为 Gmail服务似乎正在从我的URL中剥离=。因此,电子邮件的正文最终看起来是这样的: ... 显然,这种联系是行不通的 我在这里检查了其他问题,并且尝试使用GAS Utilities服务的工具,以及encodeURI()JavaScript方法。到目前

我真的很难发送一封自动电子邮件(使用谷歌应用程序脚本),其中包含一个包含查询参数的URL

预期行为 谷歌应用程序脚本(特别是
Gmail
服务)发送一封电子邮件,电子邮件正文的一部分包含一个带有查询参数的URL。URL将如下所示:

观察到的行为
Gmail
服务似乎正在从我的URL中剥离
=
。因此,电子邮件的正文最终看起来是这样的: ...

显然,这种联系是行不通的

我在这里检查了其他问题,并且尝试使用GAS Utilities服务的工具,以及
encodeURI()
JavaScript方法。到目前为止运气不好

电子邮件发送代码 您能帮忙吗?

基于正则表达式的解决方案 在塔奈克和拉法·吉列尔莫的帮助下,最终对我有效的解决方案是用
=替换
=
使用一点
.replace()
如下:
listingUrl=listingUrl.replace(/=,“=;”)

在我的环境中,很遗憾,我无法使用您的脚本复制您的问题。我可以复制此问题@主
=
会一直保留在代码中,直到消息发送。但是,如果您签出
⋮ > 显示原始的
从UI中,您可以看到文本部分实际上存在
=
,但在html部分中已被删除。然而,Logging
Utilities.newBlob(模板,“message/rfc822”).getDataAsString()
会将其显示为
=
。在我看来,这辆车很轻便@Master也尝试了
rfc2822
,但结果是相同的
=
。我们将尝试用python库复制这一点,看看这是API还是GAS包装器的问题。@Rafa Guillermo我认为这是一个很好的评论。我没有注意到这种情况发生在HTML主体上。对于文本体,
http://my.app/products?id=xyz
可以正确地看到。所以我认为OP的情况无法复制。当使用HTML正文时,我认为应该从
http://my.app/products?id=xyz
http://my.app/products?id=xyz
可能是一种解决方法。在本例中,
Gmail.Users.Messages.send(message,“me”)
也可以使用。@Tanaike将
=
替换为
=绝对有效。但是,我不确定不呈现html的简单邮件应用程序是否会直接显示为
=而不是呈现
=
。此外,我也无法使用python库复制它,因此我认为这是GAS包装器中的编码问题。
    //////// 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"))