Skip to main content
1-Visitor
November 23, 2017
Question

Email body formatting

  • November 23, 2017
  • 2 replies
  • 2105 views

Hi,

this may be a bit of a simplistic question for some of you but I wanted to know how I can format the body text of the email alerts I send out. Currently I just use a plain text string, but it doesn't look particularly professional. I understand (or can read up on) html tags, what I don't understand is how I can enter dynamic data (property values) into the html. The dynamic data can be different every time

so currently I would do something like below where the values in bold are taken from the asset properties.

var params =

{

subject: "Fault State on ASSET " + source /* STRING */,

from: "my.iot@gmail.com (do not reply)" /* STRING */,

to: "user1@gmail.com" /* STRING */,

bcc: "user2@gmail.com" /* STRING */,

body: "Remote Asset " +source+" (" + me.MachineName + ") has encountered a fault!      [1."+row.eventid+" "+row.description+"]. If problem persists please contact your local supplier"

};

// no return

Things["My.MailServer"].SendMessage(params);

Would anyone have a couple of examples, or point me in the direction of some documentation?

Thanks,

K

2 replies

1-Visitor
November 23, 2017

Hi! Just include your HTML as part of the body parameter string. Say, you want to write the source in bold:

body: "Remote Asset <b>" +source+"</b> (" + me.MachineName + ") has encountered a fault!"

If your HTML includes attributes remember to escape the double quotes (\") or use single quotes.

khayes11-VisitorAuthor
1-Visitor
December 4, 2017

Hi,

thank for the reply, appreciate you taking the time. I did try the above, but unfortunately it didn't work for me. The result was an email body as shown below

"Remote Asset <b>" +source+"</b> (" + me.MachineName + ") has encountered a fault!"


Any ideas where I might have gone wrong?

Thanks,

K