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 realize automatic mass sending of salary slips in mailbox

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to use Python to achieve automatic mass mailbox payroll". In daily operation, I believe many people have doubts about how to use Python to realize mailbox automatic mass payroll. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the doubt of "how to use Python to realize mailbox automatic mass payroll". Next, please follow the editor to study!

Libraries you need to use:

Openpyxl

Smptlib

Email.mime.text

Email.header

Implement step 1 to get the data of excel table wb = load_workbook ('data table .xlsx') sheet = wb.activefor row in sheet: for cell in row: print (cell.value) 2 to write email content

Use strings to concatenate into html

For row in sheet: tbody =''cnt + = 1 if cnt = 1: for cell in row: thead + = f' {cell.value} 'thead + =' 'else: for cell in row: tbody + = f' {cell.value}' tbody + =''name = row [ 0] .value mail = row [1] .value # 2. Write the content of the email content = favored'{name}, hello

Please check your salary from May 1 to May 31, 2025.

{thead} {tbody}''3 send email # send email class Test: def ck_log (self): pass def send_email (self, econtent, ename Mail): host = 'smtp.qq.com' user =' your email address' password = 'your authorization code' receivers = [mail] subject = 'employee payroll' msg = MIMEText (econtent, 'html' 'utf-8') msg [' From'] = Header ('Limited') msg ['To'] = Header (ename) msg [' Subject'] = Header (subject, 'utf-8') try: obj = smtplib.SMTP_SSL (host, 465) obj.login (user, password) obj.sendmail (user, receivers) Msg.as_string () print ("email sent successfully!") Except smtplib.SMTPException as e: print ("Error: unable to send mail") print (e) all code from openpyxl import load_workbookimport smtplibfrom email.mime.text import MIMETextfrom email.header import Header'''1. Get the data of excel table 2. Write email content 3. Send email class Test: def ck_log (self): pass def send_email (self, econtent, ename, mail): host = 'smtp.qq.com' user =' 1479898695 salary qq.com password = 'bijoplffwqqlbaci' receivers = [mail] subject =' employee payroll 'msg = MIMEText (econtent,' html') 'utf-8') msg [' From'] = Header ('Limited') msg ['To'] = Header (ename) msg [' Subject'] = Header (subject, 'utf-8') try: obj = smtplib.SMTP_SSL (host, 465) obj.login (user, password) obj.sendmail (user, receivers) Msg.as_string () print ("email sent successfully!") Except smtplib.SMTPException as e: print ("Error: unable to send mail") print (e) if _ _ name__ = ='_ main__': wb = load_workbook ('datasheet .xlsx') o = Test () cnt = 0 sheet = wb.active thead =''# 1. Get the data of excel table for row in sheet: tbody =''cnt + = 1 if cnt = 1: for cell in row: thead + = f' {cell.value} 'thead + =' 'else: for cell in row: tbody + = f' {cell.value} 'tbody + =' 'name = row [0] .value mail = row [1] .value # 2. Write the content of the email content = favored'{name}, hello

Please check your salary from May 1 to May 31, 2025.

{thead} {tbody}'# 3. Send email if cnt = = 3: print ('content:', content) print (name, mail) o.send_email (content, name, mail) so far, the study on "how to use Python to automatically send mass payroll in mailboxes" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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