Sendmail Errno[61] Connection Refused

前端 未结 7 1114
不思量自难忘°
不思量自难忘° 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:32

    For whatever reason, I had difficulty passing server and port to the constructor, but not the connect function. This ended up working for me:

        s = smtplib.SMTP(timeout=30) #seconds
        s.connect(EMAIL_HOST, EMAIL_PORT)
        m = MIMEText('see subject')
        m['subject'] = 'sweet subject'
        m['from'] = EMAIL_FROM
        m['to'] = to_list  # comma-separated list of emails
        s.sendmail(m['from'], m['to'].split(','), m.as_string())
        s.quit()
    

提交回复
热议问题