The example of this article is about Python's method of automatically sending mail to QQ group members. Share to everyone for your reference. The implementation methods are as follows:
Principle:
We need to first get all the members of the QQ group and save to a txt text, and then read the file by Python and then bulk mail sent, the specific solution is as follows:
1. QQ group members to obtain QQ numbers, QQ group member information can be obtained in the following Web page, select all members saved in TXT can
Http://qun.qzone.qq.com/group#!/123456/member
(Here's 123456 for QQ group number)
2. Analysis of the QQ group members to obtain a list of list.txt, to each member automatically send the message, the sender is used here is 163 mailbox
The complete script is as follows:
Copy Code code as follows:
#coding: Utf-8
Import Random
Import Smtplib
From Email.mime.text import Mimetext
Import time
def send_mail (mailto):
print ' Setting mimetext '
Ct=open (' Content.txt ', ' R ') #读取发送邮件内容
Content=ct.read (). Decode (' Utf-8 ')
Msg=mimetext (Content.encode (' UTF8 '), _subtype= ' HTML ')
Ct.close () #关闭文件
msg[' from ']=mail_user
msg[' SUbject ']=u ' python mail send test '
msg[' to ']=mailto
Try
print ' connectting ', mail_host
S=smtplib. Smtp_ssl (mail_host,465)
print ' Login to Mail_host '
S.login (MAIL_USER,MAIL_PWD)
print ' Send Mail '
S.sendmail (mail_user,mailto,msg.as_string ())
print ' Close the connection between the mail server '
S.close ()
Except Exception as E:
Print "Exceptioin", E
Def sendqunmail ():
Try
F=open (filelist, ' R ')
Lines=f.readlines ()
For I in range (Len (lines)-1):
If Lines[i].find (') <>-1 and Lines[i].find (') ') <>-1:
Qqnum=lines[i].split (' (') [1].split (') ') [0]
If Qqnum.isdigit ():
mailto=qqnum+ ' @qq. com '
print ' Sendmail to: ' +mailto
Send_mail (mailto)
Time.sleep (10)
Except Exception,ex:
Print Filelist,ex
If __name__== "__main__":
Mail_host= ' smtp.163.com '
Mail_user= ' test@163.com '
Mail_pwd= ' test123 '
Filelist= ' List.txt '
Sendqunmail ()
I hope this article will help you with your Python programming.