Sendmail Errno[61] Connection Refused

前端 未结 7 1129
不思量自难忘°
不思量自难忘° 2021-01-31 08:28

I\'ve been trying to get my application to mail some outputted text to an email. For simplification I have isolated the script :

import smtplib
import sys
import         


        
7条回答
  •  广开言路
    2021-01-31 08:34

    If you don't want to run a separate server, and if you're only using Unix, you can use this technique, copied from http://www.yak.net/fqa/84.html, and originally from the Python FAQ:

    On Unix, it's very simple, using sendmail. The location of the sendmail program varies between systems; sometimes it is /usr/lib/sendmail, sometime /usr/sbin/sendmail. The sendmail manual page will help you out. Here's some sample code:

    SENDMAIL = "/usr/sbin/sendmail" # sendmail location
    import os
    p = os.popen("%s -t" % SENDMAIL, "w")
    p.write("To: cary@ratatosk.org\n")
    p.write("Subject: test\n")
    p.write("\n") # blank line separating headers from body
    p.write("Some text\n")
    p.write("some more text\n")
    sts = p.close()
    if sts != 0:
        print "Sendmail exit status", sts
    

提交回复
热议问题