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

Plain text email?

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

Jul 19 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 27 Jun 2005 15:38:59 -0700, Inkiniteo <ga****@gmail.com> 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 ?
Jul 19 '05 #2

P: n/a
On 27 Jun 2005 15:38:59 -0700, rumours say that "Inkiniteo"
<ga****@gmail.com> 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', 't***@sil-tec.gr', ['t***@sil-tec.gr'])

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
Jul 19 '05 #3

P: n/a
On 27 Jun 2005 15:38:59 -0700, rumours say that "Inkiniteo"
<ga****@gmail.com> 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', 't***@sil-tec.gr', ['t***@sil-tec.gr'])

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
Jul 19 '05 #4

P: n/a
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****@email.com', email, message)
server.quit()

Jul 19 '05 #5

P: n/a
On 27 Jun 2005 16:09:38 -0700, rumours say that "Inkiniteo"
<ga****@gmail.com> 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('e****@email.com', 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
Jul 19 '05 #6

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


Jul 19 '05 #7

P: n/a
"Inkiniteo" <ga****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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


Jul 19 '05 #8

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

Jul 19 '05 #9

P: n/a
On 27 Jun 2005 18:56:27 -0700,
"Inkiniteo" <ga****@gmail.com> 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/>
Jul 19 '05 #10

P: n/a
"Inkiniteo" <ga****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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


Jul 19 '05 #11

P: n/a
On 27 Jun 2005 18:56:27 -0700, rumours say that "Inkiniteo"
<ga****@gmail.com> 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
Jul 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.