Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize QQ Mail's Group E-mail by python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This "python how to achieve QQ Mail mass email" article, the article sample code introduction is very detailed, with a certain reference value, interested friends must refer to, for "how to achieve QQ Mail mass email python", the editor sorted out the following knowledge points, please follow the pace of the editor step by step slowly understand, then let us enter the topic.

First, log in to the mailbox and get the authorization code

Second, replace the parameters

To send mailboxes to multiple people, I just made a loop and looped in each person's authorization code. Just replace the authorization code and mailbox with your own, and you can define the content yourself.

Import smtplibfrom email.mime.text import MIMETextfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMultipartfrom email.mime.application import MIMEApplicationfrom sql_chi import * import datetimeclass Phpson: def _ _ init__ (self,msg_from,passwd,msg_to): self.sql_pool = My_mysql_connPool (max_connections=1 * * info) self.msg_from = msg_from # sender mailbox self.passwd = passwd # fill in the authorization code of sender mailbox (the authorization code you just got) self.msg_to = msg_to # recipient mailbox # # file_path = 'demo.xlsx' # attachment directory self.text to be sent _ content = "this parameter is the content of the message" # this is particularly important # is written as a general function interface If you want to use it directly, just remove the comments of the parameters def send_email (self, file_path=None): finishTime = datetime.datetime.now () msg = MIMEMultipart () subject = f "{finishTime} crawl News data Total" # topic text = MIMEText (self.text_content) msg.attach (text) # docFile = 'CGREGUGUSUserMain.py' if you need to add attachments Given the path if file_path: # the initial function parameters I set None by default and want to add attachments Just change it yourself docFile = file_path docApart = MIMEApplication (open (docFile, 'rb'). Read () docApart.add_header (' Content-Disposition', 'attachment', filename=docFile) msg.attach (docApart) print (' send attachment!') Msg ['Subject'] = subject msg [' From'] = self.msg_from msg ['To'] = self.msg_to try: s = smtplib.SMTP_SSL ("smtp.qq.com", 465) s.login (self.msg_from, self.passwd) s.sendmail (self.msg_from, self.msg_to Msg.as_string () print ("send success") except smtplib.SMTPException as e: print ("send failed") finally: s.quit () fs = ['97679', "wangqi"] # sender mailbox sq = ['widr', "wihxa"] # fill in the authorization code of the sender mailbox (the authorization code you just got) sj = [97679' "wangq"] # recipient mailbox for i in range (len (fs)): wqx = Phpson (FS [I], sq [I], sj [I]) wqx.Dintes () wqx.send_email () what can python do Python is a programming language Built-in many effective tools, Python almost omnipotent, the language is easy to understand, easy to start, powerful, in many fields, such as the most popular big data analysis, artificial intelligence, Web development and so on.

The above is all the contents of the article "how to achieve QQ Mail's mass email by python". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report