[SMTPLIB] how to send a "Multiline" mail with smtplib?

Evan xdicry at gmail.com
Thu Jun 19 03:57:18 EDT 2008


Hello -

I'm new with Python, I try to do a mail problem, the code likes below:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import smtplib
import mimetypes
from email.Encoders import encode_base64
from email.MIMEAudio import MIMEAudio
from email.MIMEBase import MIMEBase
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText


msg = MIMEMultipart()
msg['From'] = 'ab at xx.net'
msg['To'] = 'ab at xx.net'
msg['Subject'] = 'test subject'

body=MIMEText('hello,\r\n ok',_subtype='html',_charset='windows-1255')
msg.attach(body)

server = smtplib.SMTP('mail.xx.net')
server.sendmail('ab at xx.net', 'ab at xx.net', msg.as_string())
server.quit()


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I try to use "\r\n" or "\n", but no luck, nothing with them, I still
get a Single-line text in the mail.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hello, ok
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

So how do I send a multiline mail? such as :
+++++++++++++++++++++++++++++++++++++++++++
Hello,
1,
2,
ok
+++++++++++++++++++++++++++++++++++++++++++

I would like to get help from you, thanks so much.



More information about the Python-list mailing list