0

I've got an email that populates when the sheet is edited. But the body of the mail displays strange line breaks that aren't in my code.

My code:

function processEdit(e) {
  MailApp.sendEmail({
    to:"me@gmail.com",
    subject: "The Saleable Indicator Report has been Updated",
    body: "Please go into the Parts Purchasing tab in the Saleable Indicator Report Folder and see the changes.\n\nMake sure to Supersede parts that are active in your branch to the new part numbers.\n\nThank you so much!"
  });
}

This should appear as:

Please go into the Parts Purchasing tab in the Saleable Indicator Report Folder and see the changes.

Make sure to Supersede parts that are active in your branch to the new part numbers.

Thank you so much!

But instead it comes out as this with the line breaks:

Please go into the Parts Purchasing tab in the Saleable Indicator
Report Folder and see the changes.

Make sure to Supersede parts that are active in your branch to the new part
numbers.

Thank you so much!

The line breaks between "Indicator - Report" and "part - numbers" aren't supposed to be there. I'd like to be able to add other things to this, hyperlinks and things, but I'd settle for HTML so that the line breaks aren't automatically entered when each line gets to a certain number of characters. Which I've read can only be done when you have an HTML body.

I am not savvy at this, but the videos and tutorials get me way off track since I'm not looking to send this to a lot of people or the names in the sheet.

3
  • 1
    Hi. You described how the text comes out - and clearly this is not what you want. So would you please edit your question to include an example of how you do want the text to appear. BTW, do you know that \n means 'insert a newline in the text'. That is, the text appears exactly how it is formatted; so it is important that you show how you want it to appear and we can assist you to make the necessary changes.
    – Tedinoz
    Sep 8 at 14:33
  • Than you Tedinoz! I've edited the question to include the strange page breaks. The \n are ok, that's where I'm putting new lines in, but the plain text only lets so many characters be on a line, and since there's only a few words that get bumped it looks a bit choppy. Sep 9 at 15:12
  • 1
    sendEmail has the ability to explicitly have html content. Have you tried that? Nothing has changed since this WebApps Q&A How to Send Html Emails in Google Spreadsheet
    – Tedinoz
    Sep 10 at 21:53
0

First you have to create the HTML, then assign it to the htmlBody property of the object set as sendMail parameter

Example:

function processEdit(e) {
  const html = '<p>Please go into the Parts Purchasing tab in the Saleable Indicator Report Folder and see the changes.</p><p>Make sure to Supersede parts that are active in your branch to the new part numbers.</p><p>Thank you so much!</p>'
  MailApp.sendEmail({
    to:"me@gmail.com",
    subject: "The Saleable Indicator Report has been Updated",
    body: "Please go into the Parts Purchasing tab in the Saleable Indicator Report Folder and see the changes.\n\nMake sure to Supersede parts that are active in your branch to the new part numbers.\n\nThank you so much!",
    htmlBody: html
  });
}

Regarding the line-breaks being added in the "wrong-place" that happens because the value set for the body property is used for the plain-text part of the email message which is automatically wrapped at certian line length.

Related

Not the answer you're looking for? Browse other questions tagged or ask your own question.