473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2747
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****@thirdto wer.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'.decod e('utf8').encod e('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.c z', 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*******@your thirdtower.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('str ing_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
12094
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 use PHP to get inside an OWA (Microsoft Outlook Web Access) website to send email that way? The reason I ask is because my corporate office is going to do away with our rogue SMTP server access and force everything through Exchange
1
2294
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 web page file to my hosting company, which is running Windows 2000, and I get this error message: CDO.Message.1 error '80040220' The "SendUsing" configuration value is invalid. /mailplay.asp, line 63
15
3321
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. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function isPPC() { if (navigator.appVersion.indexOf("PPC") != -1) return true; else return false;
1
1857
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 port 25 of the mail server. Works nice, but I can only send Emails to addresses on the same domain as mine (I'm me@myhost.net. I can send to you@myhost.net, but not myfriend@someotherprovider.com). I get a code back from the RCPT TO: command of...
5
2334
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 $entete = "From: $from \n";
4
1374
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 internet address eg barry@gmail.com try {
1
1459
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 where a link to them is sent to every user. - the second is to create an dynamic link to a php page with the same idea, send a HTML or text message with a link for the report.
3
8189
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 fine, but I need to set and send a cookie with the WebRequest. How do I do that?
4
3824
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 confirmation email with a link to activate the account. Nothing hi-tech here. However, it fails to send the email and provides the following error message: Transaction failed. The server response was: sorry, the sender name and auth login doesn't...
1
3443
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" cellspacing="0"> <tr> <td><div align="center" class="textorange1"><strong>Richiesta Ricarica</strong></div></td> </tr> <tr> <td>&nbsp;</td>
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.