Ask Your Question

Adding a newline to e-mail body

asked 2018-05-16 00:55:27 +0200

Mirador gravatar image

updated 2018-05-16 10:11:54 +0200

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

I am running LO 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("")
eMessage = eMailer.createSimpleMailMessage()
eMessage.Recipient = eMailAddr
eMessage.Subject = "Your next appointment " + dTdate
eMessage.Body = eMsg
eMailer.sendSimpleMailMessage (eMessage,

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..."

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("")
eMessage = eMailer.createSimpleMailMessage()
eMessage.Recipient = eMailAddr
eMessage.Subject = "Your next appointment " + dTdate
eMessage.Body = eMsg
eMailer.sendSimpleMailMessage (eMessage,

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-05-16 07:04:57 +0200

Ratslinger gravatar image

updated 2018-05-16 07:44:06 +0200


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 ✔ (upper left area of answer). It helps others to know there was an accepted answer.

edit flag offensive delete link more


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?

Mirador gravatar imageMirador ( 2018-05-16 10:16:15 +0200 )edit

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?

Mirador gravatar imageMirador ( 2018-05-16 10:24:14 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2018-05-16 15:16:59 +0200 )edit

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.

Mirador gravatar imageMirador ( 2018-05-16 18:41:28 +0200 )edit

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.

Mirador gravatar imageMirador ( 2018-05-16 19:29:09 +0200 )edit

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?

Mirador gravatar imageMirador ( 2018-05-16 19:52:04 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2018-05-16 20:08:45 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-16 00:55:27 +0200

Seen: 34 times

Last updated: May 16