Simple implementation of Python to send text messages
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 #@Time: 2018/4/25 17:095 #@Author: Zms6 #@Site:7 #@File: sendemail.py8 #@Software: pycharm Community Edition9 Ten Import Time One fromEmail.mime.textImportMimetext A ImportSmtplib - - the classSendEmail (object): - def __init__(self): -Self.port = 25 -Self.fromemail ='[email protected]' +SELF.EMAILPASSWD ='******' - + defSendEmail (self, subject, MSG, Fromemail=none, Emailpasswd=none, toemail=None): A " "implementing the Send mail function" " at ifFromemail = = None | EMAILPASSWD = =None: -_user =Self.fromemail -_pwd =self.emailpasswd - Else: -_user =Fromemail -_pwd =emailpasswd in_to =Toemail -Nowtime = Time.strftime ('%y-%m-%d%h:%m:%s') to +msg =mimetext (msg) -msg["Subject"] =subject themsg[" from"] =_user *msg[" to"] =_to $ Panax Notoginseng Try: - #s = smtplib. Smtp_ssl (' ****.****.cn ', +) thes = smtplib. SMTP (' * * *. ****.cn', Self.port) + S.login (_user, _pwd) A S.sendmail (_user, _to, msg.as_string ()) the s.quit () + Print "[%s]info:%s Email send success!"%(Nowtime, _to) - exceptSmtplib. Smtpexception, E: $ Print "[%s]error:%s Email send falied,%s"%((Nowtime, E), _to) $ - - if __name__=='__main__': theemail =SendEmail () -Email.sendemail ('Test','Test','[email protected]','******','[email protected]')
Python implementation sends text messages