Skip to main content
added 2 characters in body
Source Link
user0
  • 27.1k
  • 10
  • 53
  • 78

How about this modification? You can send an email including images using inlineImages of Advanced parameters at MailApp.sendEmail()MailApp.sendEmail(). You have already been able to retrieve the image blob. In this modified script, the blob is used.

Modified script:

function sendImage(){
  var sheet = SpreadsheetApp.getActive().getActiveSheet();
  var fileUrl = sheet.getRange('C2').getValue();
  var index = fileUrl.indexOf('=') + 1;
  var fileId = fileUrl.substring(index);
  var img = DriveApp.getFileById(fileId).getBlob();
  
  MailApp.sendEmail({
    name: "my Name",
    to: '[email protected]',
    subject: "Test 1",
    htmlBody: "<img src=\"cid:sampleImage\">", // Modified
    inlineImages: {sampleImage: img} // Modified
  });
}

Reference:

How about this modification? You can send an email including images using inlineImages of Advanced parameters at MailApp.sendEmail(). You have already been able to retrieve the image blob. In this modified script, the blob is used.

Modified script:

function sendImage(){
  var sheet = SpreadsheetApp.getActive().getActiveSheet();
  var fileUrl = sheet.getRange('C2').getValue();
  var index = fileUrl.indexOf('=') + 1;
  var fileId = fileUrl.substring(index);
  var img = DriveApp.getFileById(fileId).getBlob();
  
  MailApp.sendEmail({
    name: "my Name",
    to: '[email protected]',
    subject: "Test 1",
    htmlBody: "<img src=\"cid:sampleImage\">", // Modified
    inlineImages: {sampleImage: img} // Modified
  });
}

Reference:

How about this modification? You can send an email including images using inlineImages of Advanced parameters at MailApp.sendEmail(). You have already been able to retrieve the image blob. In this modified script, the blob is used.

Modified script:

function sendImage(){
  var sheet = SpreadsheetApp.getActive().getActiveSheet();
  var fileUrl = sheet.getRange('C2').getValue();
  var index = fileUrl.indexOf('=') + 1;
  var fileId = fileUrl.substring(index);
  var img = DriveApp.getFileById(fileId).getBlob();
  
  MailApp.sendEmail({
    name: "my Name",
    to: '[email protected]',
    subject: "Test 1",
    htmlBody: "<img src=\"cid:sampleImage\">", // Modified
    inlineImages: {sampleImage: img} // Modified
  });
}

Reference:

Source Link
Tanaike
  • 1.1k
  • 7
  • 10

How about this modification? You can send an email including images using inlineImages of Advanced parameters at MailApp.sendEmail(). You have already been able to retrieve the image blob. In this modified script, the blob is used.

Modified script:

function sendImage(){
  var sheet = SpreadsheetApp.getActive().getActiveSheet();
  var fileUrl = sheet.getRange('C2').getValue();
  var index = fileUrl.indexOf('=') + 1;
  var fileId = fileUrl.substring(index);
  var img = DriveApp.getFileById(fileId).getBlob();
  
  MailApp.sendEmail({
    name: "my Name",
    to: '[email protected]',
    subject: "Test 1",
    htmlBody: "<img src=\"cid:sampleImage\">", // Modified
    inlineImages: {sampleImage: img} // Modified
  });
}

Reference: