2017-01-18 8 views
0

python 2.7でthe mailer module(Windowsにpipにインストール)を使用すると、ASCII以外の文字を使用するとエンコーディングエラーが発生します。私はこれを試してみたメーラモジュールのエンコーディングエラー

Stuff with special characters like ?? or ?? 

message.Body = "Stuff with special characters like à or ç".decode('utf-8') 

message = mailer.Message() 
message.From = "[email protected]" 
message.To = "[email protected]" 
message.Subject = "Test" 
message.Body = "Stuff with special characters like à or ç" 

mailer = mailer.Mailer('my_relay-smtp') 
mailer.send(message) 

は、その後、私は、次の電子メールを受信

インポートメーラー:次のコードでたとえば

(または(encode)。

Use the charset property to send messages using other than us-ascii

だから、あなたが使用する必要があります:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 35: ordinal not in range(128) 

答えて

1

答えは、クラスメッセージのためのヘルプストリングに明示的である。しかし、私はエラーを取得する

message = mailer.Message(charset='utf8') 
message.From = "[email protected]" 
message.To = "[email protected]" 
message.Subject = "Test" 
message.Body = "Stuff with special characters like à or ç".decode('utf-8') 

mailer = mailer.Mailer('my_relay-smtp') 
mailer.send(message) 
+0

どのように私はそれを欠場だろうか? :/ –

関連する問題