2013-02-02 4 views
5

Markdownフォーマットを使用してtext/plainメッセージを作成し、text/htmlの部分がMarkdownから生成されたmultipart/alternativeメッセージに変換したいとします。 私は、メッセージを作成するPythonプログラムを介してこれをフィルタにfilterコマンドを使用しようとしましたが、メッセージが正しく送信されないようです。コードは以下の通りです(これは私がすべてでmultipart/alternativeメッセージを作ることができるかどうかを確認するだけのテストコードです。マルチパート/代替メールを作成するためにmuttでPythonを使用

import sys 
from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 

html = """<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 
""" 

msgbody = sys.stdin.read() 

newmsg = MIMEMultipart("alternative") 

plain = MIMEText(msgbody, "plain") 
plain["Content-Disposition"] = "inline" 

html = MIMEText(html, "html") 
html["Content-Disposition"] = "inline" 

newmsg.attach(plain) 
newmsg.attach(html) 

print newmsg.as_string() 

残念ながら、muttの中で、あなただけ(ヘッダあなたが構成するフィルタコマンドに送信されたメッセージ本文を取得します。含まれていないが、私はこの作業を取得したら、私は値下げ部分があまりにも難しいことではないだろうと思う)です

答えて

1

更新:。誰かがPythonスクリプトを使用するためのmuttの設定に関する記事を書いた私は自分自身を行うことがありません。それはhashcash and mutt、muttrcの設定を行ってコード例を示します。


旧答え

それはあなたの問題を解決していますか?

#!/usr/bin/env python 

from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 


# create the message 
msg = MIMEMultipart('alternative') 
msg['Subject'] = "My subject" 
msg['From'] = "[email protected]" 
msg['To'] = "[email protected]" 

# Text of the message 
html = """<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 
""" 
text="This is HTML" 

# Create the two parts 
plain = MIMEText(text, 'plain') 
html = MIMEText(html, 'html') 

# Let's add them 
msg.attach(plain) 
msg.attach(html) 

print msg.as_string() 

プログラムを保存してテストします。

python test-email.py 

与える:私は実行するプログラムを得ることができます

Content-Type: multipart/alternative; 
boundary="===============1440898741276032793==" 
MIME-Version: 1.0 
Subject: My subject 
From: [email protected] 
To: [email protected] 

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

This is HTML 
--===============1440898741276032793== 
Content-Type: text/html; charset="us-ascii" 
MIME-Version: 1.0 
Content-Transfer-Encoding: 7bit 

<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 

--===============1440898741276032793==-- 
+0

を、私は私の問題は、Muttはコン中のヘッダを持つメッセージのフィルタリングを許可していないということだと思います。私はこれを行うにはmuttに変更が必要だと思います。 –

+0

だから、Pythonの問題ではありません。よくわかりません。 – karlcow

+0

私は、 'multipart/alternative'メッセージが生成されるようにmuttでこのスクリプトを実行するにはどのようにすればよいのでしょうか? –

関連する問題