0

I want to use python to send an email with two rows(lines) of text like this

a    b    c    d
e    f    g    h

I tried to use xxx.attach() but I found that the second row is replaced the first one.

part1 = MIMEText(text1, 'plain')
part2 = MIMEText(text2, 'plain')
msg.attach(part1)
msg.attach(part2)

So, I tried to define each line as a string variable and then combine it together. Finally, I attach only one variable.

A="a   b   c   d"
B="e   f   g   h"

How to combine A and B to get the result as above?

PS. I am using Python3.6 on Windows10

NaC
  • 13
  • 5

2 Answers2

0

Since you're using Windows, which has a different line separation character than Linux/Unix, you can use join + the os's native line separator.

import os
A = "a   b   c   d"
B = "e   f   g   h"
C = os.linesep.join([A,B])

MIMEText could be different, especially if you're using any encoding other than text/plain. Try this post if your email message is HTML rather than plain text.

kdd
  • 436
  • 3
  • 9
0

Use the os module for this

import os
A = "a   b   c   d"
B = "e   f   g   h"
temp = os.linesep.join([A,B])
Max
  • 1,283
  • 9
  • 20