Adding a newline to e-mail body

Can anyone tell me how to add newlines to an email message body when using eMessage.Body ?

I am running LO 5.1.6.2 on Linux MINT 18.2.

For example:

eMsg = "Dear sir,\n\n"
eMsg = "This is a polite reminder of your next appointment.\n\n"
eMsg = "Appointment date: " & aDate & "\n"
eMsg = "Appoitment time: " & aTime & "\n"
eMsg = ... etc, etc, etc
eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
eMessage = eMailer.createSimpleMailMessage()
eMessage.Recipient = eMailAddr
eMessage.Subject = "Your next appointment " + dTdate
eMessage.Body = eMsg
eMailer.sendSimpleMailMessage (eMessage, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)

When the message is opens in Thunderbird, all of the text is on one continuous line. I have also tried & chr(10) & chr(13) as well as %0A %0D without any success

I have also used:

eMessage.Body = "Dear sir,\n\n"
eMessage.Body  = eMessage.Body + "This is a polite reminder of your next appointment..."
etc

It makes no difference. I need to compose a message body that consists of several lines of text. Surely this must be possible? I have done it before in Python, Perl etc, but it seems not to work in LO?

UPDATE: I hit upon the idea of displaying the body of the message (either eMsg or eMessage.Body) using MsgBox. I then found that Chr(10) or Chr(13) with upper case ‘C’ does indeed insert line breaks. I have therefore revised the above to:

eMsg = "Dear sir," + Chr(13) + Chr(13)
eMsg = eMsg + "This is a polite reminder of your next appointment."  + Chr(13) + Chr(13)
eMsg = eMsg + "Appointment date: " + aDate + Chr(13)
eMsg = eMsg + "Appoitment time: " + aTime + Chr(13)
eMsg = eMsg + "... etc, etc, etc"
eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
eMessage = eMailer.createSimpleMailMessage()
eMessage.Recipient = eMailAddr
eMessage.Subject = "Your next appointment " + dTdate
eMessage.Body = eMsg
eMailer.sendSimpleMailMessage (eMessage, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)

Unfortunately, Thunderbird still produces just one long line of text in the body of the message.

Hello,

Replace Chr(13) with "<br />".

HTML carriage return.

Also had a problem with your eMsg lines overwriting each other. Changed mine to (for test hard coded date & time):

eMsg = "Dear Sir:" + "<br />" + "<br />"
eMsg1 = "This is a polite reminder of your next appointment." + "<br />" + "<br />"
eMsg2 = "Appointment date: " + "05/16/2018" + "<br />"
eMsg3 = "Appointment time: " + "8 a.m." + "<br />"
objMessage.Body = eMsg + eMsg1 + eMsg2 + eMsg3

Note also that , after Sir was replaced with colon because nothing sent after comma. Not into HTML so can’t say why this was. Result:

image description

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

Thank you very much for your efforts. I made a mistake when I copied the eMsg lines into the post. My actual code reads:

eMsg = eMsg + “line of text”

eMsg1, eMsg2 etc works just as well though. I have edited the third snippet to reflect this.

I tried using <br /> as you suggested (with and without the space) but all I get is
instances of <br /> in the body of the message. Curious that it worked for you, as is the issue with the comma you mention. Are you running this on Windows or Linux?

Could it be down to adding something like ‘Content-Type: text/plain; charset=“UTF-8”’ or ‘Content-Type: text/HTML; charset=“UTF-8”’? I added this as the first line of the body, but it just displays the line instead of interpreting it as a container. Is there a way of setting this in the eMessage object?

My system is Linux Mint 18. Did find setting in Thunderbird where chr(13) worked. It is a matter of composing in text or HTML. See this post for more info → How to select composing mode. There are possibly other items you may have set which could be causing some of the problem.

BTW - using LO 6.0.4

Yours seems to be somewhat older. May consider upgrading.

Just a further update. I tried running this with a different e-mail software package called Geary, which is another GUI client. This appeared as an option in system preferences and I selected it to be the default e-mail client and tried the script again. This time it opened in Geary as expected and the formatting was just fine. I go back to Thunderbird and test the composing mode suggestion. Will also see whether I can upgrade LO. Just running the version from the MINT/Ubuntu repository.

Ha! The changing the composing mode worked! Thanks. I did look for such a setting but couldn’t find it because I was looking in Preferences, so thanks for posting that link. I didn’t think to look under the account specific settings.

Thanks for helping me to sort that out. I would actually like it to work in both Plain Text and HTML so I will now experiment a bit more with the HTML tags a bit further.

BTW, ThunderBird has a command line flag to set text mode. Is there a way in LO of adding command line parameters to whatever command is used to call the e-mail client?

Not aware of a method to do so. If I discover one will post it here.