Plain text email?

Discussion in 'Python' started by Inkiniteo, Jun 27, 2005.

  1. Inkiniteo

    Inkiniteo Guest

    Hi guys. I have a script that sends the info by email, but i'd like to
    avoid the convertion to HTML by the email client or Gmail, because it
    ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    be able to send SMTP mail and the receiver only get it in plain text.
     
    Inkiniteo, Jun 27, 2005
    #1
    1. Advertising

  2. On 27 Jun 2005 15:38:59 -0700, Inkiniteo <> wrote:
    > Hi guys. I have a script that sends the info by email, but i'd like to
    > avoid the convertion to HTML by the email client or Gmail, because it
    > ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    > be able to send SMTP mail and the receiver only get it in plain text.
    >


    Can you give a short example of how you are building the email ?
     
    Tim Williams (gmail), Jun 27, 2005
    #2
    1. Advertising

  3. On 27 Jun 2005 15:38:59 -0700, rumours say that "Inkiniteo"
    <> might have written:

    >Hi guys. I have a script that sends the info by email, but i'd like to
    >avoid the convertion to HTML by the email client or Gmail, because it
    >ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    >be able to send SMTP mail and the receiver only get it in plain text.


    Please tell us what you do more precisely:

    * do you send the "info" as an attachment using the email package?
    * do you create alternative text and HTML parts for the body?

    I have never managed to send plain text email and receive it as HTML.
    Perhaps you mean that some "smart" client does something stupid with
    your text, eg. it removes line-breaks you have in your message?


    Try this:

    import smtplib

    def send(server, from_whom, to_whom_list):
    smtp = smtplib.SMTP(server)
    smtp.sendmail(from_whom, to_whom_list,
    """From: %s
    To: %s
    Subject: test email

    This is a test.
    It has line breaks.
    Does it come as three separate lines?""")

    I tried it as

    send('localhost', '', [''])

    and I had no problem. What happens for you (substitute other server and
    email addresses, obviously :) ?
    --
    TZOTZIOY, I speak England very best.
    "Dear Paul,
    please stop spamming us."
    The Corinthians
     
    Christos TZOTZIOY Georgiou, Jun 28, 2005
    #3
  4. On 27 Jun 2005 15:38:59 -0700, rumours say that "Inkiniteo"
    <> might have written:

    >Hi guys. I have a script that sends the info by email, but i'd like to
    >avoid the convertion to HTML by the email client or Gmail, because it
    >ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    >be able to send SMTP mail and the receiver only get it in plain text.


    Please tell us what you do more precisely:

    * do you send the "info" as an attachment using the email package?
    * do you create alternative text and HTML parts for the body?

    I have never managed to send plain text email and receive it as HTML.
    Perhaps you mean that some "smart" client does something stupid with
    your text, eg. it removes line-breaks you have in your message?


    Try this:

    import smtplib

    def send(server, from_whom, to_whom_list):
    smtp = smtplib.SMTP(server)
    smtp.sendmail(from_whom, to_whom_list,
    """From: %s
    To: %s
    Subject: test email

    This is a test.
    It has line breaks.
    Does it come as three separate lines?""" % (from_whom,
    ", ".join(to_whom_list))

    I tried it as

    send('localhost', '', [''])

    and I had no problem. What happens for you (substitute other server and
    email addresses, obviously :) ?
    --
    TZOTZIOY, I speak England very best.
    "Dear Paul,
    please stop spamming us."
    The Corinthians
     
    Christos TZOTZIOY Georgiou, Jun 28, 2005
    #4
  5. Inkiniteo

    Inkiniteo Guest

    Humm. I just create the message this way:

    message = 'Serie:\t\t' + str(type) + str(series) + \
    '\t\t\tUbicación:\t\t\t' + place + '\n' + \
    'Date&Time:\t' + date

    and send it with:
    message = header + message
    server = smtplib.SMTP('localhost')
    server.sendmail('', email, message)
    server.quit()
     
    Inkiniteo, Jun 28, 2005
    #5
  6. On 27 Jun 2005 16:09:38 -0700, rumours say that "Inkiniteo"
    <> might have written:

    >Humm. I just create the message this way:


    >message = 'Serie:\t\t' + str(type) + str(series) + \
    > '\t\t\tUbicación:\t\t\t' + place + '\n' + \
    > 'Date&Time:\t' + date


    >and send it with:
    >message = header + message
    >server = smtplib.SMTP('localhost')
    >server.sendmail('', email, message)
    >server.quit()


    And what goes wrong when you see the message? (BTW you don't have a
    newline before "Ubicación:"; is it intentional?)

    Tabs are infamous confusers of email clients, unfortunately.
    --
    TZOTZIOY, I speak England very best.
    "Dear Paul,
    please stop spamming us."
    The Corinthians
     
    Christos TZOTZIOY Georgiou, Jun 28, 2005
    #6
  7. Hi,

    I had the exact opposite problem :)

    Hope this helps

    Regards,

    Philippe



    #********************************************************************
    def Mail(self,p_data): #data is string of text

    you = wx.GetTextFromUser('EMAIL ADDRESS','ID')
    if len(you) == 0:
    return

    self.__m_config = Config()

    self.__m_config.Load()

    me = self.__m_config.dict['ACCOUNT']
    host = self.__m_config.dict['SMTP']
    s = smtplib.SMTP()
    s.connect(host)


    s.login(me,self.__m_config.GPW())

    the_text = p_data
    msg = MIMEText(the_text)

    # ***************GET RID OF THIS LINE TO HAVE PLAIN TEXT
    ************************************
    msg.replace_header('Content-Type', 'text/html')
    # ***************GET RID OF THIS LINE TO HAVE PLAIN TEXT
    ************************************
    #msg.add_header('Content-Type', 'text/html')

    msg['To'] = you
    msg['Subject'] = self.__m_title
    msg['From'] = self.__m_config.dict['FROM']
    s.sendmail(me, [you], msg.as_string())
    self.__m_list = []



    Inkiniteo wrote:

    > Hi guys. I have a script that sends the info by email, but i'd like to
    > avoid the convertion to HTML by the email client or Gmail, because it
    > ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    > be able to send SMTP mail and the receiver only get it in plain text.
     
    Philippe C. Martin, Jun 28, 2005
    #7
  8. Inkiniteo

    John Roth Guest

    "Inkiniteo" <> wrote in message
    news:...
    > Hi guys. I have a script that sends the info by email, but i'd like to
    > avoid the convertion to HTML by the email client or Gmail, because it
    > ruins all the formatting i did (with tabs, mostly). Briefing, i wanna
    > be able to send SMTP mail and the receiver only get it in plain text.


    As long as your mimetype is text/plain you should have
    minimal trouble. There's no way you can control what
    the recipient's mail client does, however.

    In particular, there are a lot of mail clients out there that
    handle tabs poorly. Outlook Express is the poster child
    for this: it ignores tabs completely, however it is by no
    means the only culprit. It's simply the most widespread one.

    In other words, use strings of spaces rather than tabs,
    and you'll probably find your messages coming out
    looking better.

    John Roth
    >
     
    John Roth, Jun 28, 2005
    #8
  9. Inkiniteo

    Inkiniteo Guest

    I see. So... what about sending HTML email? If i send HTML tagged text,
    the client will be able to read it as HTML?

    For example, if i send an email with: <header></header> <body>
    <b>Yo!</></body> will the client read a bold Yo! ?

    Because i can replace tabs with tables if this is possible.
     
    Inkiniteo, Jun 28, 2005
    #9
  10. Inkiniteo

    Dan Sommers Guest

    On 27 Jun 2005 18:56:27 -0700,
    "Inkiniteo" <> wrote:

    > I see. So... what about sending HTML email? If i send HTML tagged
    > text, the client will be able to read it as HTML?


    > For example, if i send an email with: <header></header> <body>
    > <b>Yo!</></body> will the client read a bold Yo! ?


    That depends on the client.

    IMO, HTML belongs on web pages, not in email. YMMV.

    Regards,
    Dan

    --
    Dan Sommers
    <http://www.tombstonezero.net/dan/>
     
    Dan Sommers, Jun 28, 2005
    #10
  11. Inkiniteo

    John Roth Guest

    "Inkiniteo" <> wrote in message
    news:...
    >I see. So... what about sending HTML email? If i send HTML tagged text,
    > the client will be able to read it as HTML?
    >
    > For example, if i send an email with: <header></header> <body>
    > <b>Yo!</></body> will the client read a bold Yo! ?
    >
    > Because i can replace tabs with tables if this is possible.


    To send HTML, you definitely need a mimetype. Otherwise
    some clients will autodiagnose as HTML and attempt to render
    it, some won't. Strictly speaking, they shouldn't do autodetection.

    I also agree with Dan - HTML mail is evil, and I try to avoid it
    whenever possible. That's one of the major vectors for worms,
    viri and simliar malware.

    John Roth
    >
     
    John Roth, Jun 28, 2005
    #11
  12. On 27 Jun 2005 18:56:27 -0700, rumours say that "Inkiniteo"
    <> might have written:

    >I see. So... what about sending HTML email? If i send HTML tagged text,
    >the client will be able to read it as HTML?


    I agree with the others that HTML is part of the web, not of the e-mail
    system.

    I suggest you send your "info" as an attached text file; no client will
    mess with it. The email package is your friend for MIME messages.
    --
    TZOTZIOY, I speak England very best.
    "Dear Paul,
    please stop spamming us."
    The Corinthians
     
    Christos TZOTZIOY Georgiou, Jun 28, 2005
    #12
    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. Matthew Lenz
    Replies:
    0
    Views:
    535
    Matthew Lenz
    Feb 22, 2005
  2. Jeff Thies

    mailto link in plain text email

    Jeff Thies, Dec 23, 2004, in forum: HTML
    Replies:
    3
    Views:
    3,623
    Mark Parnell
    Dec 23, 2004
  3. TimmyC
    Replies:
    0
    Views:
    1,563
    TimmyC
    Jun 8, 2007
  4. Rohit
    Replies:
    0
    Views:
    361
    Rohit
    Oct 18, 2008
  5. Irishmaninusa

    Sending email both as html and plain text

    Irishmaninusa, Nov 13, 2003, in forum: ASP General
    Replies:
    2
    Views:
    127
    Irishmaninusa
    Nov 14, 2003
Loading...

Share This Page