views:

56

answers:

2

I am doing simple formatting for an email with StringBuilder and have code that looks like the following.


StringBuilder message = new StringBuilder();
            message.append("Name: " + model.getName() + "\r\n");
            message.append("Organization: " + model.getOrganization() +"\r\n");
            message.append("Comment: " + model.getComment() +"\r\n");
            contactMessage.setMessage(message.toString());

I am logging the formatting and it works correctly, but it is coming out as one line when we actually check the emails being sent.

What if I am not using HTML though is my real question...thanks for the help.

+3  A: 

What is the format of your email? If the format is HTML newline characters will be ignored and you'd need to insert HTML breaks <br />.

StringBuilder message = new StringBuilder();
message.append("Name: " + model.getName() + "<br />");
message.append("Organization: " + model.getOrganization() +"<br />");
message.append("Comment: " + model.getComment() +"<br />");
contactMessage.setMessage(message.toString());
brainimus
+2  A: 

If you are formatting HTML emails, then you need to use:

StringBuilder message = new StringBuilder();
         message.append("Name: " + model.getName() + "<br />\n");
         message.append("Organization: " + model.getOrganization() +"<br />\n");
         message.append("Comment: " + model.getComment() +"<br />\n");
         contactMessage.setMessage(message.toString());

You need to insert a html line break because the newlines are ignored.

jjnguy