0

Google App scripts noob here. I am trying to send email from google sheets and I have a working code. However, the challenge I have unaddressed is to paste an image in the email before sending it. The image that needs to be pasted is copied from the snipping tool. In Microsoft Outlook, I have used .Show function to preview the email and paste the image but I am unable to achieve the same in google app scripting. The image is different every time an email is sent and saving the image to a drive location defeats the automation effort so the preferred option is to paste the image before its sent. I would appreciate any suggestions and recommendations to make this happen. I am sure there is a way to do this and I am at the right place to find that way.

function SendNote() {
  
  var active_range = SpreadsheetApp.getActiveSpreadsheet().getActiveRange();
  var env_type = SpreadsheetApp.getActiveSheet().getRange(active_range.getRowIndex(), 1).getValue();
  var count = SpreadsheetApp.getActiveSheet().getRange(active_range.getRowIndex(), 4).getValue();
  var mail_type = SpreadsheetApp.getActiveSheet().getRange(active_range.getRowIndex(), 13).getValue();
  // Check totals sales
  if (mail_type = 'Kick_Off')
  {
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("B2");
    var emailAddress = emailRange.getValues();
  
    // Send Email.
    var message = 'This is my message ' + env_type; // Second column
    var subject = 'This is the subject';
    MailApp.sendEmail('myhandle@mymail.com', subject, message);
    }
}
Alsheik
  • 39
  • 6
  • You should take a look at [this question](https://stackoverflow.com/questions/41278530). where are you seeing/storing the image before sending the email? – AMolina Sep 17 '19 at 14:21
  • The problem with that is that Apps Script runs in the server, not in your machine, so you can't just put something from your computer into the code. You'd need to have the image stored somewhere (ideally Drive) and from there you can access it. – AMolina Sep 18 '19 at 14:42
  • Hello AMolina, Thanks for referring me to a somewhat similar question. I had a quick look into the topic and it doesn't address my issue in question. The trick I am trying to pull is to paste an image which is in system memory to the email before it is sent out. In simple terms, when the email is triggered, I would like to to see it in preview mode before its sent. This gives me the options to make changes to the email and paste an image, etc before its sent. – Alsheik Sep 18 '19 at 14:42
  • Gotcha. I guess then I may have to refine the business process and gauge if saving will be an option that users prefer to do as it will easier to just send a manual email. Can I refer you to another post that had some flavor to my question but couldn't understand the mechanics to get it working? Here you are [Link](https://stackoverflow.com/questions/25225529/google-apps-script-preview-the-email-before-sent-from-google-spreadsheet). Hope you may be able to grasp how to incorporate the suggestion from the thread to address my issue – Alsheik Sep 18 '19 at 14:48
  • Btw thank you for your swift and helpful responses – Alsheik Sep 18 '19 at 14:49
  • Happy to help! I took a look at that question and it seems to be about seeing the preview of the email, but if you were going to do this just to paste the image, wouldn't it negate using apps scripts, since you'll have to do it manually. I was thinking that if you have access to the images, you could paste them in a Spreadsheet and access them from there to add to the email. – AMolina Sep 19 '19 at 06:09
  • Valid thought. I may endeavour the pasting in spreadsheet route. Need to figure out the other factors such as size growth and the usability of rows to ensure it doesn't affect an average user. Will fill in when I have more info on this path. Thank you – Alsheik Sep 20 '19 at 12:40
  • No problem, if you could have them in a Drive folder it would also make your work much easier! – AMolina Sep 20 '19 at 14:04

0 Answers0