2

使用方法について質問があります。html 形式のメールを送信する必要があります。私はメッセージを準備します

ga = libgmail.GmailAccount(USERNAME,PASSWORD)
msg = MIMEMultipart('alternative') 
msg.attach(part1)
msg.attach(part2)
...
ga.sendMessage(msg.as_string())

この方法ではうまくいかずmsg、sendMessage メソッドで送信できないようです。正しい方法は何ですか?:D

4

1 に答える 1

1

sourceforgeから参照する場合は、電子メールモジュールlibgmailを使用してメッセージを作成する必要があります。

HTMLメッセージをMIMEドキュメントとして生成し、マルチパートMIMEメッセージの一部として含めます。完全に構築されたマルチパートMIMEがある場合は、 toメソッドlibgmailを使用して、それを文字列としてコンストラクターに渡します。.as_string()

ドキュメントの例には、同様の要件のコードが含まれています。

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
...
# Record the MIME types of both parts - text/plain and text/html.
# ... text and html are strings with appropriate content.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
于 2009-02-22T13:40:48.773 に答える