简体   繁体   English

将带有不同 PDF 的电子邮件发送到不同的电子邮件附件

[英]send email with different PDFs to different emails attachment

I am trying to do automate send email to multiple sender(10 emails) with different PDFs(10).我正在尝试使用不同的 PDF(10)自动向多个发件人(10 封电子邮件)发送电子邮件。 Is there a way to attach a pdf in the spreadsheet column next to email address?有没有办法在电子邮件地址旁边的电子表格列中附加 pdf? Then send email with sales quote in pdf as attachment.然后以 pdf 格式发送带有销售报价的电子邮件作为附件。 Is this can be done in JS in google sheet.这可以在谷歌表中的JS中完成吗?

Appreciate if someone help me out.感谢有人帮助我。

If you're using Google Sheets it's possible, but you have to get creative.如果您使用的是 Google 表格,这是可能的,但您必须发挥创意。 In fact you can send emails, with javascript, from google sheets using google scripts.事实上,您可以使用 google 脚本从 google 表格中使用 javascript 发送电子邮件。 I think if you get creative with a hidden sheet in the same workbook, have a formula populate that sheet with the layout of the PDF, then export that sheet as a PDF to attach to the email... it's doable.我认为如果您在同一个工作簿中使用隐藏工作表获得创意,请使用公式填充该工作表的 PDF 布局,然后将该工作表导出为 PDF 以附加到电子邮件......这是可行的。

You may find some inspiration here .您可能会在这里找到一些灵感。

Basic send email from google sheets example here .基本从谷歌表格示例发送电子邮件在这里

So, JavaScript runs in the client side.因此,JavaScript 在客户端运行。 It means that your code is running the user browser.这意味着您的代码正在运行用户浏览器。 In a brief, you can't send emails just using JavaScript.简而言之,您不能仅使用 JavaScript 发送电子邮件。 You're going to need a server to do that.你将需要一台服务器来做到这一点。

For example, you may use Spring Boot with Java that already has a lot implemented method that makes your task, ie, sending an email, super easy.例如,您可以将 Spring Boot 与 Java 一起使用,它已经有很多实现的方法可以使您的任务(即发送电子邮件)变得非常简单。

Have a look at http://spring.io/projects/spring-boot看看http://spring.io/projects/spring-boot

You can do this by following the below steps,您可以按照以下步骤执行此操作,

  1. Uploading the 10 attachments on one google drive folder在一个谷歌驱动器文件夹中上传 10 个附件

  2. On your google sheet add the below script to get the file id在您的谷歌表上添加以下脚本以获取文件 ID

function listFilesInFolder() {

    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FileID").activate(); //The name of the google sheet is FileID in my case

    var sheet = SpreadsheetApp.getActiveSheet();
    sheet.appendRow(["File Name", "File-Id"]);

  //change the folder ID below to reflect your folder's ID (look in the URL when you're in your folder)

    var folder = DriveApp.getFolderById("*[Enter Folder ID here]*");
    var contents = folder.getFiles();

    var cnt = 0;
    var file;

    while (contents.hasNext()) {
        var file = contents.next();
        cnt++;

           data = [
                file.getName(),
                file.getId(),
            ];

            sheet.appendRow(data);
    }
}
  1. Build a simple script to send emails and have your 10 emails on one column and all the File IDs generated from the above code on the next column.构建一个简单的脚本来发送电子邮件,并将您的 10 封电子邮件放在一列,并将从上述代码生成的所有文件 ID 放在下一列。 Below is a sample script to send emails from spreadsheets,以下是从电子表格发送电子邮件的示例脚本,
function sendEmails() {

  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails").activate(); // Emails is the sheet which has the email and File ID columns

  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var lr = ss.getLastRow();

  var templateText =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).getValue();  // Template is the sheet which has my email body

  for (var i = 2;i<=lr;i++){

    var currentEmail = ss.getRange(i, 1).getValue();  //Email IDs are on the first column for me

    var currentAttachment = ss.getRange(i, 2).getValue();    //Assuming your File IDs are on the second column


    var waiver = DriveApp.getFileById(currentAttachment);
    var liabilityWaiver = waiver.getAs(MimeType.PDF);

MailApp.sendEmail(currentEmail, subjectLine, messageBody, {attachments:[liabilityWaiver],
                                                               cc:'abc@abc.com'});  // the cc is in case you want to CC someone else on the email

I hope this helps!我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM