Tuesday, January 1, 2013

Add a new line in mail use br tag instead of \n


In many cases, we may intend to email Users via from Maximo customization 
[MXServer.sendEMail(String to, String from, String subject, String message)].

While simple formatting the message body with StringBuilder, we usually start with \n new line character to add a new line as below:

StringBuilder strbuild = new StringBuilder("PO: ").append(ponum).append("\n").append(podescription).append("\n").append(poline).append("\n").append(polinedescription);

but we will find the mail message comes out as one line.

It is because, if the email format is HTML, new line characters will be ignored and we need to insert HTML line breaks <br />. For example:
StringBuilder strbuild = new StringBuilder("PO: ")).append(ponum).append("<br /> \n").append(podescription).append("<br /> \n").append(poline).append("<br /> \n").append(polinedescription);

In this, <br /> inserts new line and \n will be ignored.

No comments:

Post a Comment