JavaScript Gmail API-编码/解码垃圾URL URL'
我有一个包含一个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);
}
请
- 发送电子邮件
- 一旦将电子邮件发送到“到”地址,
检查源被渲染为:
https://i.sstatic.net/2ze9s.png “ nofollow noreferrer”>在Gmail客户端渲染
https://drive.google.com/uc?e=xportview&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
- The email is sent
- 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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我对您的问题的理解是正确的,那么以下修改如何?
来自:
到:
&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:
To:
<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. When3D
is removed, the image is shown. But, I'm worried that this might not be related to the essence of your this question.