The new year is here, send qq email blessings in batches

Because the New Year is coming, New Year greetings are indispensable. So I wonder if I can send qq emails based on the python I learned

The previous article about sending QQ mail is here: https://blog.csdn.net/hexiechuangxin/article/details/113452579

The basic idea is as follows:

  1. Get friends' QQ numbers in batch
  2. Organize the email content you want to send
  3. Send emails in bulk

The following are solved in turn.

1. Get friends' QQ numbers in batches

I searched the Internet at first, but did not find a satisfactory answer. Later I opened the qq space and pressed F12 to
find the packet capture tool (Network):
Insert picture description here
refresh it to find the appropriate data package:
Insert picture description here
create a new file in the pycharm project, and copy and paste the data package into it.

Someone may ask me why I don't need advanced ones, such as directly crawling these data with python crawler. The reason is that the QQ space needs to log in, and it also has the verification code of the puzzle, which is more troublesome. It is not as fast as I copy and paste it directly.

After that, the data is analyzed to find the qq number. This is very simple, because it is a dictionary. Just know the dictionary.
Insert picture description here

qq_list = []
qq_name = []

for i in jsondata.jsondata['data']['module_3']['data']['items']:
    qq_list.append(i['uin'])
    qq_name.append(i['name'])

2. Organize the email content you want to send

Similarly, I did not use crawlers to crawl, but copy and paste directly from the Internet, which is faster. The reason is that there are often few words about New Year's greetings on a page on the Internet (I did not find a suitable website). If you use a crawler, it is enough to crawl multiple pages.

The copied and pasted string can be wrapped in a list.

text_list=['祝愿您,新年大展宏图之余:留一点时间多陪陪家人,带一份心情去看看蓝天,携一缕思念常想起朋友,存一丝宁静而处世安然猪年大吉,岁岁平安!',

'春节来临心欢畅,辞旧迎新谱新章。意气风发雄心壮,工作进步领奖状。家庭和睦美名扬,妻贤子孝人夸奖。身体健康美而壮,幸福生活把手扬。祝春节快乐!',

'春节到了,寄出原封不动的信件,将原滋原味的新春祝福,融进原原本本的心愿,愿你在新的一年,爱情圆圆满满,财富源源不断,生活花好月圆。春节快乐!',

'春节到,真热闹,家家团圆乐逍遥;吉祥话,说不完,朋友祝福莫嫌吵;祝愿你,心情好,生活幸福常微笑。祝新年快乐,一切都好!']

Three. Send emails in batches

As long as you can use python to send a single qq email, you can send it in a loop.

However, during the actual operation, I found that sending emails too fast seems to be blocked for a period of time. So set up a time.sleep(20). You can decide the specific sleep time.

Code:

import random
import smtplib
from email.mime.text import MIMEText   # 邮件正文
from email.header import Header    # 邮件头
import jsondata
import time

def send_qq_email(text1,qqemail):
    smtp_obj=smtplib.SMTP_SSL('smtp.qq.com',465)   # 发件人邮箱中的SMTP服务器,端号465
    smtp_obj.login("[email protected]","aajpzrkhkfwzdeii")   #括号中对应的是发件人的邮箱账号,邮箱秘钥
    # 设置邮件头信息
    msg=MIMEText(text1,'plain','utf-8')    # 正文
    msg['From']=Header('和谐创新','utf-8')          # 发送者
    msg['To']=Header('尊敬的您','utf-8')              # 接受者
    msg['Subject']=Header('来自zcx的祝福','utf-8')       # 主题
    # 发送
    smtp_obj.sendmail('[email protected]',qqemail,msg.as_string())

def rand_text(text_list): 
    text = text_list[random.randint(0,4)]
    return text;

text_list=['祝愿您,新年大展宏图之余:留一点时间多陪陪家人,带一份心情去看看蓝天,携一缕思念常想起朋友,存一丝宁静而处世安然猪年大吉,岁岁平安!',

'春节来临心欢畅,辞旧迎新谱新章。意气风发雄心壮,工作进步领奖状。家庭和睦美名扬,妻贤子孝人夸奖。身体健康美而壮,幸福生活把手扬。祝春节快乐!',

'春节到了,寄出原封不动的信件,将原滋原味的新春祝福,融进原原本本的心愿,愿你在新的一年,爱情圆圆满满,财富源源不断,生活花好月圆。春节快乐!',

'春节到,真热闹,家家团圆乐逍遥;吉祥话,说不完,朋友祝福莫嫌吵;祝愿你,心情好,生活幸福常微笑。祝新年快乐,一切都好!']


qq_list = []
qq_name = []

for i in jsondata.jsondata['data']['module_3']['data']['items']:
    qq_list.append(i['uin'])
    qq_name.append(i['name'])



for friend in qq_list:
    qqemail = str(friend) + '@qq.com'
    qqtext = rand_text(text_list)
    try:
        send_qq_email(qqtext,qqemail)

        print('该朋友发送完毕!邮件为:')
        print(qqemail, '\n', qqtext)
    except:
        print('该朋友邮箱错误!')

    time.sleep(20)
print(qq_name)

Guess you like

Origin blog.csdn.net/hexiechuangxin/article/details/113795397