テキスト ファイルemailtext.txt
@ http://pastie.org/8276028に HTML コードがあります。現在、次のコードを使用して (Outlook 経由で) HTML 形式の電子メールを送信していますが、書式設定が時々めちゃくちゃに見えることがあります...この電子メールを信頼できる方法で送信する方法に関する情報を提供してください。
from email.mime.text import MIMEText
from subprocess import check_call,Popen,PIPE
def email (body,subject,to=None):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html; charset=UTF8"
msg["From"] = "userid@qualcomm.com"
if to!=None:
to=to.strip()
msg["To"] = to
else:
msg["To"] = "userid2@company.com"
msg["Subject"] = '%s' % subject
p = Popen(["/usr/sbin/sendmail", "-t", "-f" + msg["From"]], stdin=PIPE)
p.communicate(msg.as_string())
print "Done"
def main ():
with open('emailtext.txt', 'r') as f:
body = f.read()
Subject ="test email"
email(body, Subject, "userid3@company.com")
if __name__ == '__main__':
main()