Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python to realize automatic mass sending of salary slips in mailbox

Shulou Source: shulou.com Published: 2022-06-01 11:38:43 10月04日 Update

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!

Tags: Email payroll mailbox data content learning success hello company employee datasheet more limited limited help practical next code character string Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux macOS Shulou Tech Info Shulou Technology