473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to send an email with non-ascii characters in Python

Lad
Can anyone give an example how to send email with non-ascii characters(
both in subject and body).
I would like to use windows-1250 code page
Thank you
L.B.

Feb 24 '06 #1
7 2735
Lad enlightened us with:
Can anyone give an example how to send email with non-ascii
characters( both in subject and body). I would like to use
windows-1250 code page


I'd use Latin-1 or UTF-8, since they are both cross-platform instead
of windows-specific...

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Feb 24 '06 #2
Lad
Sybren,
and can give me an example of Python code that can send such email??

Feb 24 '06 #3
Lad enlightened us with:
and can give me an example of Python code that can send such
email??


Not really, but I'm sure this will help you. In fact, my last name has
an umlaut on the 'u'. This is the From header in my emails, encoded in
Latin-1:

From: Sybren =?iso-8859-1?Q?St=FCvel?= <sy****@thirdtower.com>

You must ensure that there are no spaces in the specially encoded
part. So if I'd encode my first name too, it would be:

=?iso-8859-1?Q?Sybren?= =?iso-8859-1?Q?St=FCvel?=

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Feb 24 '06 #4
Lad
Finally I have the working version,It looks like this
#############
from email.Message import Message
from email.MIMEText import MIMEText
from email.Header import Header
import smtplib
msg = Message()
Body='Rídících Márinka a Školák Kája
Marík'.decode('utf8').encode('windows-1250')# I use the text written
in my editor with utf-8 coding, so first I decode and then encode to
windows-1250
msg = MIMEText(Body,'plain', 'windows-1250')#add body to email and with
proper coding
h = Header('Ceské knihy - made by Czech
Republic'.decode('utf8').encode('windows-1250'), 'windows-1250')#Also
subject should be a proper coding with
msg['Subject'] = h# add the header to the message
s = smtplib.SMTP() # and send
s.connect()
s.sendmail('e..or*@h.pe.cz', 'ex..or*@h.pe.cz', msg.as_string())
s.close()
#############
Hope it may be useful to others

Feb 25 '06 #5
Lad enlightened us with:
Body='Rídících Márinka a Školák Kája
Marík'.decode('utf8').encode('windows-1250')# I use the text written
in my editor with utf-8 coding, so first I decode and then encode to
windows-1250


Why would you do that? What's the advantage of windows-1250?

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Feb 25 '06 #6
2006/2/25, Sybren Stuvel <sy*******@yourthirdtower.com.imagination>:
Lad enlightened us with:
Body='Rídících Márinka a Školák Kája
Marík'.decode('utf8').encode('windows-1250')# I use the text written
in my editor with utf-8 coding, so first I decode and then encode to
windows-1250


what does a string became when it's decoded?

I mean, it must be encoded in something, right?
Feb 26 '06 #7
Gabriel B. wrote:
what does a string became when it's decoded?

I mean, it must be encoded in something, right?


Unicode, for encodings like latin-1 or utf-8. A few special cases like
str.decode('string_escape') yield byte strings again.

Kent
Feb 26 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
1
by: Bruce W.1 | last post by:
I'm new to ASP (but not ASP.NET) and I'm trying to setup a simple ASP web form to send an email to me. So I try this code: http://www.library.unr.edu/subjects/guides/mailplay.asp I upload the...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
1
by: StevenBarnes | last post by:
I need to have some .Net code be able to send Email using my ISP's SMTP server. I found some articles on how to use the MAIL FROM: and RCPT TO: commands that you can stream to a tcp connection on...
5
by: Thierry | last post by:
Hello. Is it possible to send an email with some HTML code ? I tried the following code, where $msg == '<html><body>... blah blab blah etc.</body></html>' : // Adresse de l'expediteur...
4
by: barry | last post by:
Hi I a developing on a Windows 2003 Server environment with MS Exchange 2003 installed, using the following code i am able to send e-mail message to Administrator@myserver.com but not to any...
1
by: Bob Bedford | last post by:
Hello all, I've to send some reports to a mailing list. Those reports must be created by datas stored in mysql, using PHP. - my first idea is to create PDF files that can be sent by email or...
3
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
4
by: gurufordy | last post by:
Hello. Trying to use the ASP.net user functionality but it keeps failing on me. I have created a login and registration page for my site. When you fill in the registration form it should send a...
1
by: toretto | last post by:
Hello, I have a script php that I use on my website to permit visitors to send me some email with some data, this is the html table code: <table width="730" border="0" cellpadding="0"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.