By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,368 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,368 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies

P: n/a
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

P: n/a
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

P: n/a
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.