From the initial implementation of the mail delivery function, changed a few times, with the following code.
The code can also continue to develop and refine. To achieve more complex functionality.
#-*-coding:utf-8-*-i = 0while i < 10:import smtplib from email.mime.text import mimetext from Email.header im Port Header Import time# third-party SMTP service mail_host= "smtp.qq.com" #设置服务器 mail_user= "[Email protected]" #发件人用户名 mail_pass= "Awlnfypgaznfbbhz" #发件人口令, QQ mailbox is the input authorization code, in the QQ mailbox set up with a verified mobile phone to send text messages, not including the space sender = ' [ Email protected] ' #与发件人用户名保持一致receivers = "[email protected]" # Recipient email address, can be set to your QQ mailbox or other mailbox message = Mimetext ( ' Content ', ' plain ', ' utf-8 ') message[' from ' = Header ("Sender", ' Utf-8 ') message[' to '] = header ("You", ' Utf-8 ') ) subject = ' title ' message[' subject ' = header (subject, ' utf-8 ') try: smtpobj = Smtplib. Smtp_ssl (Mail_host, 465) Smtpobj.login (mail_user,mail_pass) smtpobj.sendmail (sender, receivers, Message.as_string ()) smtpobj.quit () print u "Mail sent successfully" except Smtplib. Smtpexception,e: Print ei = i + 1time.sleep (' End ')
Python Mail Send source code