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 use Python to send group emails automatically

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

Share

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

This article mainly explains "how to use Python to automatically send mass email". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Python to automatically send mass email".

How to match the recipient's name one by one

Prerequisite, my interpreter is IDLE 3.6.I am used to it and do not want to upgrade it.

Take two mailboxes as an example.

To_emails= ['123 rogue qq.composer] to_names= [' robbing Kidd', 'painting pear clothes on cedar']

Automatic group mail, when dealing with the recipient's name, it is mostly handled by join function.

Forms a comma-separated string.

Officially, it is said that the data type of the first parameter accepted by Header must be a string or byte, and the list cannot be decoded.

To_names= ['rob Kidd', 'Sequoia painted pear clothes'] msg ['To'] = Header ("," .join)

But, I tried it, but it didn't work. The recipients of both mailboxes were Kidd, who was painted with pears on the mountain. I am not sure what the reason is. I do not rule out the problem of the version. Some netizens can tell me if they know it.

1. Traverse two lists

Import smtplib from email.mime.text import MIMEText from email.header import Header import time from_name = input ('Please enter Sender:') from_addr = input ('Please enter Sender email:') password = input ('Please enter Sender email Authorization Code:') to_namelist = [] to_addrs = [] number=0 while True: name=input ('Please enter recipient:') to_namelist.append (name) email=input ('Please Enter the recipient mailbox:') to_addrs.append (email) temp=input ('(can be sent in a group) whether to continue to enter the mailbox Enter n and enter to exit Enter any key to continue:') number=number+1 if temp=='n': break smtp_server = 'smtp.qq.com' input_subject = input (' Please enter email subject:') text = input ('Please enter email content:') for i in range (number): to_name=to_ namelist [I] to_addr=to_addrs [I] msg = MIMEText (text,'plain') 'utf-8') msg [' From'] = Header (from_name) msg ['To'] = Header (to_name) msg [' Subject'] = Header (input_subject) server = smtplib.SMTP_SSL () server.connect (smtp_server,465) server.login (from_addr, password) server.sendmail (from_addr,to_addr Msg.as_string () server.quit () now=time.strftime ('% Y-%m-%d% H15% MV% slots, time.localtime (time.time ()) print (now) print ('email sent successfully!')

2. Put the two lists into the Excel table through csv, and then loop by reading the Excel table.

Import time import smtplib from email.mime.text import MIMEText from email.header import Header import csv # Sender Information from_addr='1499823573@qq.com' password='xzrbanqjofkugaei' # if you have an Excel form, you don't need to create a new one. If you don't have csv, you have to consider creating a new csv file # method 1: create a new csv file # data= through the existing list [['rogue Kidd', '123 rogue qq.com'], ['painted pear clothes on Shanshan' Method 2: create a new csv file dataemail= [] dataname= [] data= [] number=0 while True: input_name=input ('Please enter the recipient's address (feel free to write):') dataname.append (input_name) input_email=input ('Please enter the recipient's email account:') dataemail.append (input_email) b=input ('whether to continue entering) N exit Any key continues:') number=number+1 if bounded mailbox data: break iTun0 for i in range (number): data.append ([dataname [I], dataemail [I]]) with open ('C:/Users/ASUS/Desktop/ mailbox data .csv','a' Newline='') as f: writer=csv.writer (f) for row in data: writer.writerow (row) input_fromname=input ('Please enter Sender:') input_subject=input ('Please enter email subject:) text=input (' Please enter mass email content:) with open ('C:/Users/ASUS/Desktop/ mailbox data .csv' 'r') as f: reader=csv.reader (f) for row in reader: to_addrs=row [1] to_name=row [0] # text='ncoqw' msg=MIMEText (text,'plain' 'utf-8') msg [' From'] = Header (input_fromname) msg ['To'] = Header (to_name) msg [' Subject'] = Header (input_subject) server=smtplib.SMTP_SSL () server.connect ('smtp.qq.com',465) server.login (from_addr,password) server.sendmail (from_addr,to_addrs Msg.as_string () server.quit () now=time.strftime ('% Y-%m-%d% HGV% MV% Shop journal time.localtime (time.time ()) print (now) print ('email sent successfully!')

There's a point here that I didn't think of at first.

Data.append ([dataname [I], dataemail [I]]) Thank you for your reading. The above is the content of "how to use Python to automatically send group email". After the study of this article, I believe you have a deeper understanding of how to use Python to automatically send group email, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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