10

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...?

froadie
  • 79,995
  • 75
  • 166
  • 235
  • 4
    is your email html formatted? That can affect the presentation of newlines... – Eric Snow Aug 26 '10 at 18:18
  • @Eric Snow - I was updating as you commented... seems you solved my problem :) If you post it as an answer I'll upvote and accept it. – froadie Aug 26 '10 at 18:20

5 Answers5

12

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>"

houbysoft
  • 32,532
  • 24
  • 103
  • 156
12

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

Eric Snow
  • 1,198
  • 8
  • 21
7

Are you reading the e-mail in Outlook? Outlook will strip "extra line breaks" (that is, those line breaks it deems unnecessary by some arcane rule) from plain text mail. To get around this, I convert mail such as logs to HTML before sending it. This is very simple; just wrap it in <PRE>... </PRE> tags (with appropriate HTML headers of course).

kindall
  • 178,883
  • 35
  • 278
  • 309
  • Outlook will also usually tell the user that it stripped extra line breaks in the notification area at the top of the message, and if you click it there should be an option to restore it. I think there is also an option burried deep in the Arcane Mystic Super-Advanced email options that lets you toggle this feature. – FrustratedWithFormsDesigner Aug 26 '10 at 18:29
0

For this type of problem, I find that looking at the native code in the eMail helps greatly. I use Eudora for this since it stores all of the eMail in native text format. I'm able to look at the formatting without having it browsed by the eMail client by opening the email mailbox in Notepad or some other text editor. If you're in a UNIX environment, it might be better to look at it in vi or another basic text editor.
All eMail is pure text and it is converted to what you see by the eMail client.

Dave
  • 1,234
  • 13
  • 24
0

Have you tried replacing \n with tag?

Solved my problem with mail.HTMLBODY using win32com for sending Outlook email.

Hope this helps.