Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline showing up on screen but not in email

I have a list (errors) that I both print to the screen and send in the body of an email. But first I separate the elements of the list with a newline character:

"\n".join(errors)

I then print it to the console and send it as an email. On the console it appears delimited by newlines:

Error generating report
Another error

In the email, however, they fail to show...

Error generating report Another error

What's going on?

Edit:

To further complicate things, I just noticed that 2 emails are sent, one of which displays the newline and one of which doesn't!

sendEmail(SUPPORT_EMAIL_ADDRESS, "application terminated unexpectedly.", \
                   "The script will exit.\n\nError Message:\n%s" % \
                   "\n".join(errors))
sendEmail(USERS_EMAIL_ADDRESS, "report is delayed.", 
                   "\n".join(errors), 
                   "html", [], [], SUPPORT_EMAIL_ADDRESS)

The first does have them while the second doesn't. Is this because of the html formatting in the second...?

like image 744
froadie Avatar asked Aug 26 '10 18:08

froadie


2 Answers

If your email is HTML formatted then that would affect presentation of newlines.

like image 55
Eric Snow Avatar answered Sep 21 '22 15:09

Eric Snow


Two things I would try:

  • try with CRLF ("\r\n") instead of just LF

  • make sure your email is not being sent in HTML mode, or, if yes, try replacing the "\n" with "<br>"

like image 24
houbysoft Avatar answered Sep 17 '22 15:09

houbysoft