Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   [SMTPLIB] how to send a "Multiline" mail with smtplib? (http://www.velocityreviews.com/forums/t621111-smtplib-how-to-send-a-multiline-mail-with-smtplib.html)

Evan 06-19-2008 07:57 AM

[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'] = 'ab@xx.net'
msg['To'] = 'ab@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@xx.net', 'ab@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.

Justin Ezequiel 06-19-2008 09:02 AM

Re: how to send a "Multiline" mail with smtplib?
 
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')

Lie 06-19-2008 10:12 AM

Re: how to send a "Multiline" mail with smtplib?
 
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 <p> tags.

Evan 06-23-2008 08:50 AM

Re: how to send a "Multiline" mail with smtplib?
 
On Jun 19, 6:12 pm, Lie <Lie.1...@gmail.com> wrote:
> 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 <p> tags.



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


All times are GMT. The time now is 02:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.