Sending mail via sendmail from python

前端 未结 8 1626
时光说笑
时光说笑 2020-12-04 12:04

If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?

Better yet, is there a good library that

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 12:44

    This is a simple python function that uses the unix sendmail to deliver a mail.

    def sendMail():
        sendmail_location = "/usr/sbin/sendmail" # sendmail location
        p = os.popen("%s -t" % sendmail_location, "w")
        p.write("From: %s\n" % "from@somewhere.com")
        p.write("To: %s\n" % "to@somewhereelse.com")
        p.write("Subject: thesubject\n")
        p.write("\n") # blank line separating headers from body
        p.write("body of the mail")
        status = p.close()
        if status != 0:
               print "Sendmail exit status", status
    

提交回复
热议问题