Plain text email?

I

Inkiniteo

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.
 
T

Tim Williams (gmail)

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 ?
 
C

Christos TZOTZIOY Georgiou

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', '(e-mail address removed)', ['(e-mail address removed)'])

and I had no problem. What happens for you (substitute other server and
email addresses, obviously :) ?
 
C

Christos TZOTZIOY Georgiou

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', '(e-mail address removed)', ['(e-mail address removed)'])

and I had no problem. What happens for you (substitute other server and
email addresses, obviously :) ?
 
I

Inkiniteo

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('(e-mail address removed)', email, message)
server.quit()
 
C

Christos TZOTZIOY Georgiou

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('(e-mail address removed)', 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.
 
P

Philippe C. Martin

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 = []
 
J

John Roth

Inkiniteo said:
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
 
I

Inkiniteo

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.
 
D

Dan Sommers

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
 
J

John Roth

Inkiniteo said:
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
 
C

Christos TZOTZIOY Georgiou

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top