Example of Python automatically sending emails to QQ group members

Source: Internet
Author: User


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 ()

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.