current position:Home>How to send payslips in Python

How to send payslips in Python

2022-02-01 13:10:55 zwf193071

This is my participation 11 The fourth of the yuegengwen challenge 5 God , Check out the activity details :2021 One last more challenge


 Every payday , Financial pain is ~~
 No literary talent , However, the above sentence shows that when people keep repeating their work , A painful state of mind .
 As procedural apes, we , Of course, you have to stand up at this time , Don't talk much , Roll up your sleeves and write .
 Copy code 

Code implementation

import openpyxl
from openpyxl import load_workbook
import yagmail
import keyring
from datetime import *

wb = load_workbook("test.xlsx", data_only = True)
sheet =

yagmail.register("[email protected]", "AAA")
pwd = keyring.get_password("yagmail", "[email protected]")
yag = yagmail.SMTP(user="[email protected]", host="", password=pwd)

for row in sheet:
    count += 1
    if count == 1:
        for cell in row:
            if cell.column != "B":
                table_header += f"<th>{cell.value}</th>"
        table_header += "</thead>"
        row_text = ""
        for cell in row:
            if cell.column == "B":
            row_text += f"<td>{cell.value}</td>"
        row_text += "</tr>"
        name = row[0].value
        email = row[1].value

        contents = f""" <h3>{name}, hello: </h3> <p>Please check your {}-{} salary.</p> <table border="1px solid black">{table_header}{row_text}</table> """
        yag.send(f"{email}", f"Wenfang limited company{}-{}-salary status", contents)
        print(f"{name} sent ")
print(" All sent ")

 Copy code 

Be careful :yagmail.register("[email protected]", "AAA"), The second parameter "AAA" It is necessary to go to QQ Obtained from mailbox settings , The steps are shown in the figure below :

  1. Click Settings  Insert picture description here
  2. Switch to 【 Account 】 One column , Click to open SMTP

 Insert picture description here There will be a shell layer , Prompt to send information to the corresponding account , After the SMS is sent successfully , You can get the parameters "AAA" Value

function python file , The following results appear  Insert picture description here

Check E-mail , New messages have been found  Insert picture description here

copyright notice
author[zwf193071],Please bring the original link to reprint, thank you.

Random recommended