SMTP is the protocol that sends messages. The Python support for SMTP has two modules, smtplib modules and email modules. emailresponsible for structuring the message, smtplib responsible for sending the message.
An example of a simple implementation of the ability to send mail
#!/usr/bin/env python# coding=utf-8import smtplibfrom email.mime.text import mimetextmail_to_list=["[email protected] "]mail_host=" smtp.126.com "mail_user=" Linux "mail_pass=" password "mail_postfix=" 126.com "def send_mail (To_list,sub, Content): me=mail_user+ "<" +mail_user+ "@" +mail_postfix+ ">" msg=mimetext (content) msg[' Subject ']=sub msg[' from ']=me msg[' to ']=; '. Join (To_list) try: s = smtplib. SMTP () s.connect (mail_host) s.login (mail_user,mail_pass) s.sendmail (Me, To_list, msg.as_string ()) s.close () return True except Exception, E: print str (e) return falseif __name__ = = ' __main__ ': if Send_mail (Mail_to_list, "This is a sub", "This is Content"): print "OK" else: print "fail"
Python implementation Send mail