Search code examples
emailgoogle-apps-scripttextgmail

Apps Script is adding line breaks to email bodies


I am generating emails with Google Apps Script and the emails are being sent with line breaks in weird places.

Here is my code

function sendEmail(){
  var name = "MyName"
  var body = name + " has issued a challenge. You already have a match currently scheduled so you have the option to decline. Reply to this email with the word 'ACCEPT' or 'DECLINE' in the subject." +
       "\n\nNOTE: If you do not respond to this email you will automatically accept the challenge and be responsible for scheduling the match within two weeks or suffer a forfeit."

GmailApp.sendEmail("[email protected]", "You've been challenged!", body)
}

here is a screenshot of the email I get

You'll notice that it is also putting the text of the first section of the body in a purple color. I also don't know why this is happening but my priority is to stop the line breaks from being put where they shouldn't be.


Solution

  • Google 'Stacks' emails. Say for example I send you an email. Then you reply and I reply again. It stacks them all into one line in your inbox.

    Any identical paragraphs in the emails are made purple. Only you see the purple.

    If you delete all of the emails out of your inbox and test again, you should notice it in black.

    Also, you have code to create two new lines. '\n' x2. You're essentially creating a new paragraph, do you just want a new line to begin instead? If so delete 1x '\n'. Sorry if I'm not understanding your issue.

    If you were to insert the body as html and use paragraph tags you would likely be able to achieve the results you are pursuing.

    I am on mobile and don't know how to get resource links to prove the above sorry.

    Edit: I would make the following change:

    body = name + " has issued a challenge. You already have a match currently scheduled so you have the option to decline. Reply to this email with the word 'ACCEPT' or 'DECLINE' in the subject." + "\n\n" +  "NOTE: If you do not respond to this email you will automatically accept the challenge and be responsible for scheduling the match within two weeks or suffer a forfeit."