1

Google App Engine で Python を使用して注文通知を送信するのが好きです。問題は、メール本文に「öäü」などの特殊文字が含まれている可能性があることですが、コンテンツ タイプから文字セットを変更する機会が見つかりません。

文字セットを charset="us-ascii" から "utf-8" に変更し、Google App Engine メール API または回避策を引き続き使用する可能性はありますか? パラメータ Content-transfer-encoding: quoted-printable を追加しますか?

ここで、通知を送信するための私のアプローチ:

from google.appengine.ext import db
from google.appengine.api import mail

from email.header import Header

def encode_mail_header(line):
    return Header(line, 'utf-8').encode()

msg = u"Message with some chars like öäüßéèô..."
subject = encode_mail_header(u"Hans Müller your Ticket")
sender = "My Service <notification+@localhost.de>"
to = encode_mail_header(u"Hans Müller")
to += " <hans.mueller@localhost>"

message = mail.EmailMessage(sender=sender,
      to=to,
      subject=subject,
      body=msg)
message.send()

開発サーバーから電子メール コードを受け取りました:

Received: from spooler by localhost (Mercury/32 v4.62); 26 Mar 2013 10:50:35 +0100
X-Envelope-To: <hans.mueller@localhost>
Return-path: <notification+@localhost.de>
Received: from [192.168.56.1] (127.0.0.1) by localhost (Mercury/32 v4.62) with ESMTP ID MG000011;
   26 Mar 2013 10:50:24 +0100
Content-Type: multipart/mixed; boundary="===============1598388400=="
MIME-Version: 1.0
To: =?utf-8?q?Hans_M=C3=BCller?= <hans.mueller@localhost>
From: My Service <notification+@localhost.de>
Reply-To:
Subject: =?utf-8?q?Hans_M=C3=BCller_your_Ticket?=
X-UC-Weight: [#   ] 51
X-CC-Diagnostic: Not Header "Date" Exists (51)

--===============1598388400==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Message with some chars like öäüßéèô...
--===============1598388400==--

手伝ってくれてありがとう

4

1 に答える 1

1

次のコードを使用します。

メッセージ = メール.EmailMessage()

message.subject = "=?utf-8?B?%s?=" % base64.b64encode( u"üäö".encode("UTF-8") )

message.html = u"üäö".encode('ascii', 'xmlcharrefreplace')

于 2013-03-26T15:18:44.153 に答える