469,907 Members | 2,170 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,907 developers. It's quick & easy.

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

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'] = 'a*@xx.net'
msg['To'] = 'a*@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('a*@xx.net', 'a*@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.
Jun 27 '08 #1
3 9695
perhaps change html

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

to plain

body=MIMEText('hello,\r\n
ok',_subtype='plain',_charset='windows-1255')
Jun 27 '08 #2
Lie
On Jun 19, 4:02*pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
perhaps change html

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

to plain

body=MIMEText('hello,\r\n
ok',_subtype='plain',_charset='windows-1255')
If that was the case, and you needed a line break in html-mode, use
<br /or <ptags.
Jun 27 '08 #3
On Jun 19, 6:12 pm, Lie <Lie.1...@gmail.comwrote:
On Jun 19, 4:02 pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
perhaps change html
body=MIMEText('hello,\r\n
ok',_subtype='html',_charset='windows-1255')
to plain
body=MIMEText('hello,\r\n
ok',_subtype='plain',_charset='windows-1255')

If that was the case, and you needed a line break in html-mode, use
<br /or <ptags.

Thanks all,
and yes, if I use "plain" or use HTML tag "<br>", it worked:
(1) HTML:
I use tag "<br />" and "&nbsp;", and when I reply that mail, I will
see "<br>" tag in mail content, it is not a good option.
thanks,
Evan
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

53 posts views Thread by Oliver Fromme | last post: by
2 posts views Thread by ae | last post: by
4 posts views Thread by Kerem Gümrükcü | last post: by
3 posts views Thread by Chris Mahoney | last post: by
11 posts views Thread by Sven | last post: by
3 posts views Thread by Frank | last post: by
71 posts views Thread by Jack | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.