Following situation: Sending emails from google spreadsheets. I have a compiled text (with line breaks), which is stored in var message.I have been trying to include a picture for the signature. To display it, I used the html body in the options parameter (as suggested here: https://developers.google.com/apps-script/reference/mail/mail-app) This is the code:function sendEmails() {var sheet = SpreadsheetApp.getActiveSheet();var range = sheet.getRange(1, 2);  // Fetch the range of cells B1:B1var subject = range.getValues();   // Fetch value for subject line from above rangevar range = sheet.getRange(1, 9);  // Fetch the range of cells I1:I1var numRows = range.getValues();   // Fetch value for number of emails from above rangevar startRow = 4;                  // First row of data to processvar dataRange = sheet.getRange(startRow, 1, numRows,9 ) // Fetch the range of cells A4:I_var data = dataRange.getValues();  // Fetch values for each row in the Range.var googleLogoUrl = http://die-masterarbeit.de/media/grafik/logo.png;var googleLogoBlob = UrlFetchApp                     .fetch(googleLogoUrl)                     .getBlob()                     .setName(googleLogoBlob);for (i in data) {var row = data[i];var emailAddress = row[0];      // First columnvar message = row[8];           // Ninth columnMailApp.sendEmail(emailAddress,             subject,             message,{name: 'Peter Peschel',htmlBody: <img src='cid:googleLogo'>,inlineImages:  {    googleLogo: googleLogoBlob,  }})};}What happens is that the message variable is not displayed at all. I have experimented in calling on the message variable in the htmlbody again, but this completely takes out the formatting (especially line breaks) of the message.MailApp.sendEmail(emailAddress,             subject,             message,{name: 'Peter Peschel',htmlBody: message + <img src='cid:googleLogo'>,inlineImages:  {    googleLogo: googleLogoBlob,  },})};}Any suggestions on how to best display the image while keeping the formatting of the message? Thanks!
E-Mail from Google Spreadsheets: including image for signature takes out formatting of message
google spreadsheets;google drive;google apps script;google apps email
You are using the format sendEmail(recipient, subject, body, options) of the MailApp.sendEmail method. As the documentation says, if options include htmlBody, it will be used instead of the body parameter. This is why your first attempt ignored message.Since you need to send an HTML message, its content must be formatted as HTML; in particular, line breaks should be <br> instead of the control character \n. Solution: replace \n with <br> in the message body. Here is an example of a script sending the content of cell A1. It provides plainMessage in case the recipient's email client does not render HTML, and htmlMessage with inline image function sendA1() {  var plainMessage = SpreadsheetApp.getActiveSheet().getRange(1,1).getValue();  var htmlMessage = message.replace(/\n/g, '<br>') + <img src='cid:googleLogo'>;   MailApp.sendEmail('user@domain.com', 'my subject', plainMessage, {     htmlBody: message,    inlineImages:      {        googleLogo: googleLogoBlob       }         }); }By the way, since you are using options extensively, it would make  sense to switch to the format sendEmail(message) where message is an object holding all the parameters. This makes for a more readable code: MailApp.sendEmail({  to:       'user@domain.com',   subject:  'my subject',   body:     plainMessage,   htmlBody: message,  inlineImages:    {      googleLogo: googleLogoBlob     }}); 