JavaScript Gmail API-编码/解码垃圾URL URL'

发布于 2025-02-09 00:04:50 字数 1559 浏览 1 评论 0原文

我有一个包含一个URL的字符串

mailMessage += '<img src=3D"https://drive.google.com/uc?export=view&id=1aA93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv" width=3D"300" alt=3D"Mountains Picture" style=3D"width:100%; height:auto; display:block; border:none; text-decoration:none; color:#363636; ">\n';

email += mailTo + "\r\n";
email += mailFrom + "\r\n";
email += mailSubject + "\r\n";

email += "Content-Type: text/html; charset=utf-8\r\n";      
email += "Content-Transfer-Encoding: quoted-printable\r\n";
email += "\r\n" + mailMessage;



,然后致电Gmail API发送消息:

 async function sendMessageGapi_new(){
    var mailRequest = await gapi.client.gmail.users.messages.send({  
       'userId': 'me',
       'resource': {
          'raw': window.btoa(email).replace(/\+/g, '-').replace(/\//g, '_')
       }
    });
   console.log(mailRequest);
 }

  1. 发送电子邮件
  2. 一旦将电子邮件发送到“到”地址,

带有损坏链接的电子邮件屏幕截图

检查源被渲染为:

https://i.sstatic.net/2ze9s.png “ nofollow noreferrer”>在Gmail客户端渲染

https://drive.google.com/uc?e=xportview&amp;id A93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv

而不是

https://drive.google.com/uc?export=view&id=1aA93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv

我在编码上做错了什么?

I have a string that contains a URL

mailMessage += '<img src=3D"https://drive.google.com/uc?export=view&id=1aA93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv" width=3D"300" alt=3D"Mountains Picture" style=3D"width:100%; height:auto; display:block; border:none; text-decoration:none; color:#363636; ">\n';

email += mailTo + "\r\n";
email += mailFrom + "\r\n";
email += mailSubject + "\r\n";

email += "Content-Type: text/html; charset=utf-8\r\n";      
email += "Content-Transfer-Encoding: quoted-printable\r\n";
email += "\r\n" + mailMessage;



I then call the gmail api to send the message:

 async function sendMessageGapi_new(){
    var mailRequest = await gapi.client.gmail.users.messages.send({  
       'userId': 'me',
       'resource': {
          'raw': window.btoa(email).replace(/\+/g, '-').replace(/\//g, '_')
       }
    });
   console.log(mailRequest);
 }

Everything works great

  1. The email is sent
  2. Once the email is delivered to 'To' address the img link is broken.

Screenshot of email with broken link

Checking the source it is being rendered as:

Checking source in gmail

html being rendered in the gmail client side

https://drive.google.com/uc?e=xportview&id A93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv

instead of

https://drive.google.com/uc?export=view&id=1aA93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv

Am I doing something wrong with my encoding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2025-02-16 00:04:50

如果我对您的问题的理解是正确的,那么以下修改如何?

来自:

email += "Content-Type: text/html; charset=utf-8\r\n";
email += "Content-Transfer-Encoding: quoted-printable\r\n";
email += "\r\n" + mailMessage;

到:

email += "Content-Type: text/html; charset=utf-8\r\n";
email += "\r\n";
email += "\r\n" + mailMessage;
  • 当我测试此修改时,&lt; img src = 3d“ https://drive.google.com/uc?export=view&amp; amp; amp;Id=1aa93wzjohkmzjcmz8jcmj4j4j4u3ejfggvm_qe2e2efgm_qe2ece2uv” width图片“样式= 3D”宽度:100%;我确认了正确的URL。但是,在我的环境中,我看不到图像。当删除3D时,显示了图像。但是,我担心这可能与您这个问题的本质无关。

If my understanding of your issue is correct, how about the following modifiaction?

From:

email += "Content-Type: text/html; charset=utf-8\r\n";
email += "Content-Transfer-Encoding: quoted-printable\r\n";
email += "\r\n" + mailMessage;

To:

email += "Content-Type: text/html; charset=utf-8\r\n";
email += "\r\n";
email += "\r\n" + mailMessage;
  • When I tested this modification, <img src=3D"https://drive.google.com/uc?export=view&id=1aA93WZJOhKMZ8JCmJ4u3ejfGVM_Qe2Uv" width=3D"300" alt=3D"Mountains Picture" style=3D"width:100%; height:auto; display:block; border:none; text-decoration:none; color:#363636; "> is sent as the HTML body, and I confirmed the correct URL. But, in my environment, I cannot see the image. When 3D is removed, the image is shown. But, I'm worried that this might not be related to the essence of your this question.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文