python发邮件

 1 #!/usr/bin/python
 2 # -*- coding:utf-8 -*-
 3 
 4 import sys
 5 import commands
 6 import smtplib
 7 from email.mime.text import MIMEText
 8 import datetime
 9 From = 'abc@qq.com'
10 To = [ 
11 'abc@qq.com'
12 ]
13 
14 def send_mail(content):
15     msg = MIMEText(content, _subtype = 'plain', _charset = 'utf-8')
16     msg['Subject'] = 'Test'
17     msg['From'] = From
18     msg['To'] = ';'.join(To)
19     try:
20         server = smtplib.SMTP('smtp.exmail.qq.com')
21         server.login('abc@qq.com', 'passwd')
22         server.sendmail(From, To, msg.as_string())
23         server.close()
24         return True
25     except Exception, e:
26         print str(e)
27         return False
28 
29 
30 
31 if __name__ == '__main__':
32     send_mail("hello")
原文地址:https://www.cnblogs.com/uangyy/p/5441439.html