Join the Mozilla’s Test Days event from Dec 2–8 to test the new Firefox address bar on Firefox Beta 134 and get a chance to win Mozilla swag vouchers! 🎁

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Programmatically creating an e-mail - how to add newlines and formatting?

  • 3 replies
  • 1 has this problem
  • 22 views
  • Last reply by forumposter

more options

I am trying to create an e-mail from LibreOffice Calc. At the present time I am not sure whether the issue is with LibreOffice or Thiunderbird, but I suspect the latter so please bear with me. I have set up the message parameters in the macro, including e-mail address, subject and message body. The message body is set up as a string variable using a series of lines like:

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"

The string variable is then passed to the eMessage object as a parameter.

The string variable seems to display fine as several lines of text in a dialogue box (MsgBox) in LO, but when passed to Thunderbird, all the text is lumped into one line and the newline characters are ignored. I have tried using the HTML BR code but this is just displayed as text. So what is missing? How does one get Thunderbird to recognize plain text or HTML formatting?

I am trying to create an e-mail from LibreOffice Calc. At the present time I am not sure whether the issue is with LibreOffice or Thiunderbird, but I suspect the latter so please bear with me. I have set up the message parameters in the macro, including e-mail address, subject and message body. The message body is set up as a string variable using a series of lines like: 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" The string variable is then passed to the eMessage object as a parameter. The string variable seems to display fine as several lines of text in a dialogue box (MsgBox) in LO, but when passed to Thunderbird, all the text is lumped into one line and the newline characters are ignored. I have tried using the HTML BR code but this is just displayed as text. So what is missing? How does one get Thunderbird to recognize plain text or HTML formatting?

All Replies (3)

more options

You would need to do one of these:

  1. copy-and-paste your created text into an existing html email message, in Thunderbird's compose window;
  2. create your email messages in plain text mode, where your formatting will make sense;
  3. bite the bullet and generate the message as an html document - that means you'll need to create the <html>, <head> and <body> sections and all the associated metadata. You could just copy-and-paste these from an unsent empty email message.

At the moment, it seems that you are composing in html mode in Thunderbird but not providing all the additional stuff needed to make it work.

Chr(13) (carriage return) is just white space to an html parser and will be ignored, as will tabs, linefeeds and maybe mulitple spaces. But a <br> string passed as text will be taken as a literal, not as html markup.

Modified by Zenos

more options

Thank you for taking the time to reply, however:

1. Not possible to do as the e-mail is not being composed as a user in Thunderbird, but via LibreOffice basic script.

2. How do I tell Thunderbird to treat my e-mail as plain text from my script?

3. Sadly, it doesn't work either. I get all of the HTML codes displayed as plain text.

I am aware that Chr(13) is the code for a carriage return and Chr(10) is for a newline. Unfortunately, neither ASCII control codes nor HTML markup works. I am happy to use either, but ASCII control codes are just ignored and HTML appears as plain text.

Just to clarify, I am writing a program in Libreoffice basic (the default macro language in the office suite) to send a custom formatted e-mail from a LibreOffice Calc spreadsheet. The program uses an API that calls whatever e-mail client is installed on the system and opens the pre-filled e-mail in the E-Mail client editor ready for final review and waiting for the user to hit the Send button. Since I am running on Linux MINT, I have Thunderbird installed. I'm not sure how the e-mail client is determined and called by the API, but it calls whatever is set as the e-mail client application in the Linux MINT System Settings.

Just to rule out the LibreOffice API, I installed another e-mail client called Geary (first time I have heard of it). After setting it up, I selected Geary as the default e-mail client application in the MINT system and then ran the macro again. The e-mail was opened in Geary this time and with the correct formatting.

This suggest to me that the problem has to do with how the e-mail data being passed by the script to Thunderbird is being treated, which seems to currently involve stripping ASCII control characters and treating printable characters, including HTML markup, as text. I don't know whether this is due to a setting in Thunderbird, or whether Thunderbird needs to be passed something to instruct it to treat the e-mail body data as either clear text or HTML depending what has been chosen. It would perhaps help to understand how Thunderbird is called and how the e-mail parameters are passed?

I would imagine that the LibreOffice API is using some form of standardized approach to call the e-mail client, otherwise it would need a driver or definition for every common e-mail client software package.

more options

Just an update: I found that switching the composition mode to text solves the problem for plain text. https://support.mozilla.org/en-US/questions/1110272 Switching to text mode allows me to program carriage returns as line endings.

However, it seems that the way forward is to use HTML, so if TB is in HTML mode by default, why is HTML markup rendered as text rather than interpreted as markup?