Python sends text messages

Source: Internet
Author: User

1 #!/usr/bin/env python2 #Coding=utf-83#Author: ca0gu0
4 Import Time5 ImportSmtplib6 fromEmail.mime.textImportMimetext7 8 classMailcli (object):9 def __init__(self):TenSelf.s = Smtplib. SMTP ()#class instantiation One A defConnect (self, host=none, port=25): -Self.s.connect (host, Port)#connecting to a mail server - the defLogin (self, user=none, passwd=None): -Self.user =User -Self.s.login (user, passwd)#login account and password - + - defSend (self, subject=none, Content=none, to=None): +Froms = self.user+'<%s>'%(Self.user) Amsg = Mimetext (content)#working with outgoing content atmsg['Subject'] = subject#working with outgoing senders topics -msg[' from'] = Froms#working with sender addresses -msg[' to'] = To#Handling Recipient addresses -Self.s.sendmail (Froms, To, msg.as_string ())#Send Message content - return "OK" - in defClose (self): -Self.s.close ()#Exit Login to return '0' #Show successful sending + - the if __name__=="__main__": *Host ="mail.xxx.com" $Port = 25Panax Notoginsenguser ="[email protected]" -passwd ="Password" theto ="[email protected]" + AR=mailcli () theR.connect (host=host,port=Port) +R.login (User=user, passwd=passwd) - $ forIinchRange (10): #连续发生10封邮件 $ -Subject ="Testing SMTP Authentication"+Str (i) -Content ="This mail tests SMTP authentication"+Str (i) thereturns = R.send (Subject=subject, Content=content, to=to ) - PrintTime.strftime ("%y-%m-%d%h:%m:%s", Time.localtime (Time.time ())), returnsWuyiR.close ()

Python sends text messages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.