This article describes the Python implementation of the QQ group to automatically send messages to members of the method. Share to everyone for your reference. The implementation method is as follows:
Principle:
We need to 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 member QQ number, QQ group member information can be obtained in the following pages, select all members saved in TXT can
Http://qun.qzone.qq.com/group#!/123456/member
(123456 here is QQ Group number)
2. Resolve the QQ group member list List.txt, to each member automatically send the message, the sender is used here is 163 mailbox
The complete script is as follows:
The code is 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 ()
Hopefully this article will help you with Python programming.