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

Discussion in 'Python' started by Evan, Jun 19, 2008.

  1. Evan

    Evan Guest

    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'] = ''
    msg['To'] = ''
    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('', '', 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.
     
    Evan, Jun 19, 2008
    #1
    1. Advertising

  2. 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')
     
    Justin Ezequiel, Jun 19, 2008
    #2
    1. Advertising

  3. Evan

    Lie Guest

    Re: how to send a "Multiline" mail with smtplib?

    On Jun 19, 4:02 pm, Justin Ezequiel <>
    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.
     
    Lie, Jun 19, 2008
    #3
  4. Evan

    Evan Guest

    Re: how to send a "Multiline" mail with smtplib?

    On Jun 19, 6:12 pm, Lie <> wrote:
    > On Jun 19, 4:02 pm, Justin Ezequiel <>
    > 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
     
    Evan, Jun 23, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    3
    Views:
    1,960
    Larry Lard
    Nov 23, 2005
  2. =?Utf-8?B?Unlhbg==?=
    Replies:
    2
    Views:
    3,925
    Steven Cheng[MSFT]
    Feb 28, 2006
  3. refv8
    Replies:
    2
    Views:
    27,120
    ittower
    Oct 13, 2006
  4. 星星

    smtplib send mail dns resolve problem

    星星, Oct 19, 2009, in forum: Python
    Replies:
    2
    Views:
    757
    星星
    Oct 20, 2009
  5. dale zhang
    Replies:
    8
    Views:
    438
    Tintin
    Nov 30, 2004
Loading...

Share This Page