I’m wondering if it is possible to format the text in either an email or Notification. For example, I have a rule to send an email each time my garage door is opened.
sendMail("xxxx@xxx.com", "Garage Door Opened", "The Garage Door was opened at " + Date.state.format("%tr") + " on "+ Date.state.format("%tD") + ".")
Is it possible to add bold or other text formatting to the email? Show the date or time in a red, etc?
Or add line breaks? Or possibly even create the email in html and then pass that into the rule?
Yeah, I’ve tried stuff like < b> my text < /b> and <font color="“red”">my text without success.
Edit. Unsure why the above is not showing the closing < /font >
The code for most bulletin boards and forums is slightly different then the html code from what I remember. I wonder if even possibly to create something with css and stylesheet?
I think it may be possible to create a full html document and pass into a rule? But doing that would then lose (I think) the ability to pass variables into the text for the Item Name, date/time, etc?
I tried as well with BBCode like [ color=red] mytest [ /color] and [ b] mytext [/b] but the email just shows with that as unformatted text.
So maybe both BBCode and html/css cant’ be done at this time. And not an important thing, and only just trying to learn more on what can be done with email and notifications.
I was only guessing/thinking you could perhaps load an html, text, or other document in for the body of the email.
But I believe using StringBuilder or appending variables together is not actually doing any formatting of text. I did find you can do a line break with \n but haven’t found options yet on actually edit the text font size, bold, color, etc… if that’s even possible.
Again, I’m just learning here what my options are. Everything works very well as it currently is and only seeing what else I can possible learn and edit.
Did someone solve the point of formatting email text? Would be a very nice feature creating tables and stuff like that. Emails would be much more clearer and just looking nicer having such a feature.
I had a go trying to format an email using the technique described but I am obviously missing something as it comes through at the destination in the same text form rather than being interpreted as HTML and producing a nice formatted email.
heres the example I used, perhaps you could advise further?
Please note I had to escape the single and double quotes embedded in the message.
Unfortunately that did not work and top close the gap I have included a screenshot of what turns up in my gmail email destination. in case it provides a clue.
I have removed all the escaped ’ and " characters
and added the html tags and also a the DOCTYPE line to the top.
See the attached txt file which I have given a pdf extension to allow it to be uploaded, simply rename the file extension to html and it will load into a browser nicely
I am thinking of testing it out by sending it using mail/sendmail/mutt to see if they work and it is simply a limitation of the sendMail action in OH2 Test-Email.pdf (2.3 KB)
I’m not saying that this is the issue, but I ran the HTML code through a validator and while there were some minor errors, this one could be part of your trouble…
I’ve run into HTML mail issues before when they don’t pass validation.
Might be a wild goose chase but wanted to give you my .02 based on my experience.
Squid
Line 43, Column 7: end tag for "HTML" which is not finished
</html>
✉
Most likely, you nested tags and closed them in the wrong order. For example <p><em>...</p> is not acceptable, as <em> must be closed before <p>. Acceptable nesting is: <p><em>...</em></p>
Another possibility is that you used an element which requires a child element that you did not include. Hence the parent element is "not finished", not complete. For instance, in HTML the <head> element must contain a <title> child element, lists require appropriate list items (<ul> and <ol> require <li>; <dl> requires <dt> and <dd>), and so on.
I saw the validator throw the same error; damned if I could find the issue though.
rather than dive into a W3C validator rabbit hole I have simplified the html body, this is strict doctype tentative pass
Same issue when sent so either this issue is somewhere else or I am making the same mistake in this simple html file
The escaping is still going on, is this throwing a spanner in the works?
I will check out your point about email client later today. I was sending it to gmail and looking on the web client but will try with outlook later so I have more control and visibility of what was received.