如何用python群发工资条

前言

每逢工资发放日,便是财务痛苦时~~
没啥文采,不过上面这句话却道出了人在不停重复劳作时,一种痛苦的心态。
身为程序猿的我们,这个时候当然要挺身而出啦,话不多说,撸起袖子写吧。

代码实现

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

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

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

count=0
table_header=""
for row in sheet:
    count += 1
    if count == 1:
        for cell in row:
            if cell.column != "B":
                table_header += f"{cell.value}"
        table_header += ""
        continue
    else:
        row_text = ""
        for cell in row:
            if cell.column == "B":
                continue
            row_text += f"{cell.value}"
        row_text += ""
        name = row[0].value
        email = row[1].value

        contents = f"""
                

{name}, hello:

Please check your {date.today().year}-{date.today().month} salary.

{table_header}{row_text}
"""
yag.send(f"{email}", f"Wenfang limited company{date.today().year}-{date.today().month}-salary status", contents) print(f"{name}发送完毕") print("所有发送完毕")

注意点:yagmail.register(“[email protected]”, “AAA”),第二个参数"AAA"是需要去QQ邮箱设置里获取的,步骤见下图所示:

  1. 点击设置如何用python群发工资条_第1张图片
  2. 切换到【账户】一栏,点击开启SMTP
    如何用python群发工资条_第2张图片
    会出现弹层,提示发送信息给对应的账户,短信发送成功后,即可获取到参数"AAA"的值

运行python文件,出现如下结果
如何用python群发工资条_第3张图片

查看邮箱,已发现新邮件
如何用python群发工资条_第4张图片

感谢下面的作者

黄伟呢

你可能感兴趣的:(python,python,excel,smtp)