gpt4 book ai didi

GmailMessage 转 PDF

转载 作者:行者123 更新时间:2023-12-02 02:14:59 28 4
gpt4 key购买 nike

Google Apps 脚本 - Gmail

是否会实现 GmailMessage (GmailThread) .getAsPdf() 方法?预期输出与 Gmail 中可用的打印为 PDF 的输出相同。这个函数在网站上有,为什么不在脚本中呢?

这是将选定的 Gmail 对话以 PDF 格式快速分发给其他人/外部人员所必需的。

此外,GmailMessage.getAttachments()虽然在在线文档中,但实际上并不存在。会实现吗?

谢谢

最佳答案

我试过这个并且效果很好(不确定这是唯一的方法):

function getattach(){
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var message = firstThread.getMessages()[0];
var attach = message.getAttachments();
Logger.log(attach[0].getDataAsString() )
if(attach.length>0){
var file=DocsList.createFile(attach[0])
var pdf=file.getAs('application/pdf').getBytes();
// for test purpose I send the pdf as attachment
var attach_to_send = {fileName: 'pdftest.pdf',content:pdf, mimeType:'application/pdf'};
MailApp.sendEmail('emailadress@gmail.com', 'Your test as PDF ', 'see attachment', {attachments:[attach_to_send]});
file.setTrashed(true);// delete after use ;-)
}
}

编辑 1:删除

编辑 2:这是一个新版本,正文为 pdf 附件,也支持 html(使用 DocsList 服务),删除了临时文档。一言以蔽之:非常令人满意;-)

function getAttachAndBody(){
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var message = firstThread.getMessages()[0];
var attach = message.getAttachments();
var body = message.getBody();//is a string
var bodydochtml = DocsList.createFile('body.html', body, "text/html")
var bodyId=bodydochtml.getId()
var bodydocpdf = bodydochtml.getAs('application/pdf').getBytes();
if(attach.length>0){
var file=DocsList.createFile(attach[0])
var pdf=file.getAs('application/pdf').getBytes();
var attach_to_send = {fileName: 'pdftest.pdf',content:pdf, mimeType:'application/pdf'};
var body_to_send = {fileName: 'body.pdf',content:bodydocpdf, mimeType:'application/pdf'};
MailApp.sendEmail('emailadress@gmail.com', 'transfer email as pdf : body & attachment', 'see attachment', {attachments:[attach_to_send,body_to_send]});
file.setTrashed(true);
DocsList.getFileById(bodyId).setTrashed(true)
}
}

关于GmailMessage 转 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11069475/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com