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
(123456 for QQ group number)
2. Resolve to get the QQ group member list List.txt, to each member automatically send a message, the sender is used here is 163 mailbox
The complete script is as follows:
The code is as follows |
Copy Code |
#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 () |