setevoy
setevoy

Reputation: 4662

Format list in email

I have script, which collect some data:

...
REPORT = []
...
if re.search('^-', line):
    logging.info('File %s in line %d: %s' % (file, num, line))
    REPORT.append('File %s in line %d: %s' % (file, num, line))
...

And then send email:

body = email.mime.Text.MIMEText("""

Report:

%s

""" % REPORT)

msg.attach(body)

But it's arrives in 'raw' view, like:

Report:

['File services.PROD.properties in line 29: - \r\n', 'File services.PROD.properties in line 30: - Url=https://someurl.com/reporting\r\n', 'File services.properties in line 44: - gUrl=http://someurl.com:11704/uu.dll\r\n', ']

How can I format it to send usual lines/strings?

Python 2.6

Upvotes: 0

Views: 35

Answers (1)

falsetru
falsetru

Reputation: 369274

Use str.join to join strings with newline:

>>> '\n'.join(['line1', 'line2', 'line3'])
'line1\nline2\nline3'
>>> print('\n'.join(['line1', 'line2', 'line3']))
line1
line2
line3

body = email.mime.Text.MIMEText("""

Report:

%s

""" % '\n'.join(REPORT))

Upvotes: 3

Related Questions