473,788 Members | 2,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with email package

Hallöchen!

I thought that with the following code snippet, I could generate a
MIME email stub:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from email.MIMEText import MIMEText
from email.Generator import Generator
import sys

message = MIMEText(u"Hall öchen!", _charset="utf-8")
Generator(sys.s tdout).flatten( message)

However, MIMEText doesn't see that u"Hallöchen! " is a unicode and
encodes it accoring to _charset. Additionally, it is encoded as
base64 (why?). But okay, I added some lines to work around it:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from email.MIMEText import MIMEText
from email.Generator import Generator
from email.Charset import Charset
import sys

charset = Charset("utf-8")
charset.body_en coding = None
message = MIMEText(u"Hall öchen!".encode( "utf-8"), _charset="utf-8")
message.set_cha rset(charset)
Generator(sys.s tdout).flatten( message)

However, the result of this is

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

Hallöchen!

The Content-Transfer-Encoding is wrong. Okay (well, not okay but)
then I added message["Content-Transfer-Encoding"] = "8bit" to my
code and got

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Transfer-Encoding: 8bit

Hallöchen!

I mean, I can work around anything, but is the email package just
rather buggy or do I something completely misguided here? Thanks
for any hints!

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber. org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Jul 16 '07 #1
2 1466
Hallöchen!

Ingrid Bronger writes:
[...]

The Content-Transfer-Encoding is wrong. Okay (well, not okay but)
then I added message["Content-Transfer-Encoding"] = "8bit" to my
code and got

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Transfer-Encoding: 8bit

Hallöchen!
I found the cause of this part of my trouble.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber. org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Jul 16 '07 #2
Hi there,
What was the solution you found?
Could you please post it? I'm having the same problem... ;o(
Thanks!
Harel

On Jul 16, 2:53 pm, Torsten Bronger <bron...@physik .rwth-aachen.de>
wrote:
Hallöchen!

Ingrid Bronger writes:
[...]
The Content-Transfer-Encoding is wrong. Okay (well, not okay but)
then I added message["Content-Transfer-Encoding"] = "8bit" to my
code and got
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Transfer-Encoding: 8bit
Hallöchen!

I found the cause of this part of my trouble.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: bron...@jabber. org
(Seehttp://ime.webhop.orgf or ICQ, MSN, etc.)

Jul 24 '07 #3

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

Similar topics

3
2972
by: Roger Godefroy | last post by:
Hi there, Anybody an idea which phpscript I could use for a helpdesk. E-Mail messages sent to support@blabla.com should automaticaly being transfered to the system and email the user back with a ticketnumber. After that ofcourse should be the rest for handling the tickets. If possible... freeware ;) Greetings,
4
1453
by: Lol McBride | last post by:
Hi all, I'm developing an OOP program and trying to be smart by using unittest to help me to catch as many bugs as possible during development.Unfortunately I've hit a snag which I believe is to do with namespaces (specifically the os.path). The program is split into packages and modules as below: oop_lb - toplevelpackage __init__.py oop_lb.py
3
2601
by: Phillip | last post by:
Some people tipped me off on some possibilities to tackle my https problem. Those have definitely gotten me further in cornering the problem. Thank you. But: No matter what I do to open a webconnection with httpS I always get something in this Area: urllib2.URLError: <urlopen error unknown url type: https>
3
1852
by: Charles Krug | last post by:
List: I'm trying to use the example files from Programming Python, 2nd Ed. I've copied them into c:\Python24\Examples\PP2E. Launching any of the examples programs by themselves seems to work spiffily. Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath
5
1724
by: lkrubner | last post by:
Go to this page: http://www.publicpen.com/designer/mcControlPanel.php?arrangement=createweblogsForm.php You'll need to login, use these: username: designer password: designer123 This is a demo site where we are debugging our software, please feel
1
324
by: David | last post by:
Hi, I have a form with a sub-form. The Main form shows a selected product, and the sub-form shows the package contents for that product as follows: Item | Qty | Print (Checkbox) Basically, when the sub-form loads, I want all the Item lines 'Print' check boxes CHECKED. The user can then UNSELECT certain package items
4
3290
by: Jim Bancroft | last post by:
Hi everyone, I've recently ported a COM component into .Net using a runtime callable wrapper. The component in question is SQL Server's DTS package, if that helps. The import worked well enough....now I'm having some trouble using the component. Specifically, this code below from VB6, which works: Dim oTask As DTS.Task
1
1529
by: drife | last post by:
Hello, I use the Python Numeric package extensively, and had been an avid user of the "old" scipy. In my view, both pieces of software are truly first rate, and have greatly improved my productivity in the area of scientific analysis. Thus, I was excited to make the transition to the new scipy core (numpy). Unfortunately, I am experiencing a problem that I cannot sort out. I am running Python 2.4.2 on a Debian box (V3.1), using
9
2003
Steel546
by: Steel546 | last post by:
This program is used to calculate GPA. I'm having trouble actually getting an output. Alright, I KNOW that I don't have an output statement, but I don't know where to put it... heh. Netbeans keeps telling me it's wrong. So, here's my two classes. package KyleTaylorGPA; public class GPA { private double theGPA; private int gradePointsSum;
0
10366
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
10173
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...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
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
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
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
2894
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.