テキストファイル「gerrit.txt」にHTMLコード@ http://pastie.org/8289257 があり、内容を含むテーブルを作成します。テキストファイルを.htmファイルに変換して開くと、出力は完全に見えますこれは、HTML コードに問題がないことを示していますが、以下のコードを使用して (Outlook を使用して) 電子メールを送信すると、テーブルがめちゃくちゃになることがあります。他にどのような方法で電子メールを送信できるかについてのアイデアが必要ですか?以下のように SMTP を試しましたが、うまくいかないようです...
from email.mime.text import MIMEText
from smtplib import SMTP
def email (body,subject):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html; charset=UTF8"
msg['Subject'] = subject
s = SMTP('localhost',25)
s.sendmail('userid@company.com', ['userid2@company.com'],msg=msg.as_string())
def main ():
# open gerrit.txt and read the content into body
with open('gerrit.txt', 'r') as f:
body = f.read()
subject = "test email"
email(body,subject)
print "Done"
if __name__ == '__main__':
main()