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 payroll mail in batches

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

Share

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

Today, I will show you how to use python to send payroll mail in batches. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

The format of the salary excel table is as follows:

Use python to send payroll information to each employee in the following format:

Train of thought:

The first is to load excel and get the current sheet table

Salay = load_workbook ('Datang Construction Group-May 2022 salary. Xlsx', data_only=True) ws = salay.active

Log in to the outgoing mailbox server used

# Log in to the mailbox server smtp_obj = smtplib.SMTP_SSL ('smtp.qq.com', 465) # smtp_obj.set_debuglevel (1) smtp_obj.login (' vision.wangpc@foxmail.com', "tsjodbaab") # Tencent mailbox, and the client logs in with the authorization code

There is a pit here: the account password of the mailbox login, some mailboxes are passwords, some are using authorization codes, Tencent QQ Mail uses authorization codes.

When using Sina mailbox, I can't log on to the server, the reason is unknown!

Iterate through the sheet table to get the header information.

Count = 0for row in ws: count + = 1 if count = = 1: # header information can be read once table_header =''for cell in row: table_header + = favored' {cell.value} 'table_header + =''

Read the first row of excel, construct the header, and read the first row only once, so add a count variable. Count

Table_header is the html text that constructs the payroll header information

Read each line of data, get the employee's name, mailbox and payroll information, and construct the complete content of the email body!

Else: msg_context_data =''for cell in row: # once read employee payroll msg_context_data + = favored salary' {cell.value} 'msg_context_data + =' 'mail = row [1] .value name = row [2] .value msg_context = favored salary' {name}, hello:

Please check your salary slip for 2022-05

{table_header} {msg_context_data}''

Msg_context_data is the text data in html format on the line of the payroll information

Send an email for each row of data read

Msg = MIMEText (msg_context, 'html',' GBK') msg ['from'] = Header (' xx Human Resources Department', 'GBK') msg [' To'] = Header ('name',' GBK') msg ['Subject'] = Header (' 2022.May payroll', 'GBK') smtp_obj.sendmail (' vision.wangpc@foxmail.com', mail Msg.as_string () # did not read a line of information to send an email what Python is mainly used to do Python is mainly used in: 1, Web development 2, data science research; 3, web crawler; 4, embedded application development; 5, game development; 6, desktop application development.

The above is how to use python to send payroll mail in batches of all the contents, more and how to use python batch to send payroll mail-related content can search the previous articles or browse the following articles to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!

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