0

テキスト ファイル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()
4

1 に答える 1

0

smtplib を使用してみてください:

from smtplib import SMTP
s = SMTP('localhost',25)
s.sendmail('Me <me@example.com>', ['You <you@example.com>'],msg=msg.as_string())

それでもうまくいかない場合は、HTML が間違っている可能性があります。

于 2013-08-28T14:07:38.627 に答える