Google 脚本不发送电子邮件

问题描述 投票:0回答:1

我有一个谷歌脚本,可以使用表单提交来填写文档,然后将其转换为 PDF 并保存 PDF,然后通过电子邮件将其发送到 2 个电子邮件。一封发送给电子邮件位于 Google 工作表上的受访者,另一封发送给硬编码的电子邮件地址。触发器正在工作,文档将被填写并以 PDF 格式保存到正确的文件夹中。我已验证所有指向相应表格、文档和单元格的链接均正确。 但它不会发送任何电子邮件。我是 Google 脚本新手,因此可以使用任何和所有帮助。

function afterFormSubmit(e) { 
  
    const info = e.namedValues;
    const pdfFile = createPDF(info);

    sendEmail(e.namedValues['Email Address'][0], pdfFile);
    sendEmail2(e.namedValues['Name'][0], pdfFile);
}


function sendEmail(email,pdfFile){

  GmailApp.sendEmail(email,"Cutting Edge Renovation and Painting, LLC - Acknowledgement Form Completed", "Please find a copy of the Cutting Edge Renovation and Painting, LLC Acknowledgement form you completed for your records.",{attachments:[pdfFile],
  name: 'Cutting Edge Renovation and Painting, LLC'
});
}


function sendEmail2(ClientName,pdfFile){

  GmailApp.sendEmail("[email protected]","Cutting Edge Renovation and Painting, LLC - Client Completed the Acknowledgement Form", ClientName & " " & "has completed the Acknowledgement form",{
    attachments:[pdfFile],
  name: 'Cutting Edge Renovation and Painting, LLC'
});
}


function createPDF(info){

const pdfFolder = DriveApp.getFolderById("1N2QTvSJgRMtBx7TzCIKUWc6o3JOhfuGU");
const tempFolder = DriveApp.getFolderById("1WpbEOn_zH1IdvA_PkvxeDPnMXJVVMWQj"); 
const templateDoc = DriveApp.getFileById("1QMHSL1CFb_2srVDd1YZlQEmGMTx0sHm7NGjWBZpnccE");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();

body.replaceText("{Name}", info['Name'][0]);
body.replaceText("{Address}", info['Job Address'][0]);
body.replaceText("{Photo}", info['Photo Release'][0]);
body.replaceText("{Access}", info['Home Access'][0]);
body.replaceText("{Parking}", info['Parking'][0]);
body.replaceText("{Parking2}", info['Parking Permit'][0]);
body.replaceText("{Signature}", info['Signature'][0]);
body.replaceText("{Phone}", info['Phone Number'][0]);
body.replaceText("{Date}", info['Timestamp'][0]);

openDoc.saveAndClose();

const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Name'][0]);
}
google-apps-script
1个回答
0
投票

这对我有用:

function onMyFormSubmit(e) { 
  GmailApp.sendEmail(e.namedValues['Email Address'][0],e.namedValues["2. Question "][0],"", {attachments:DriveApp.getFileById(gobj.globals.test1id)});
}
© www.soinside.com 2019 - 2024. All rights reserved.