您好,登錄后才能下訂單哦!
這篇文章給大家介紹如何使用Python郵箱自動群發工資條,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
Python主要應用于:1、Web開發;2、數據科學研究;3、網絡爬蟲;4、嵌入式應用開發;5、游戲開發;6、桌面應用開發。
openpyxl
smptlib
email.mime.text
email.header
wb = load_workbook('數據表.xlsx') sheet = wb.active for row in sheet: for cell in row: print(cell.value)
使用字符串拼接成html
for row in sheet: tbody = '<tr>' cnt += 1 if cnt == 1: for cell in row: thead += f'<th>{cell.value}</th>' thead += '</thead>' else: for cell in row: tbody += f'<td>{cell.value}</td>' tbody += '</tr>' name = row[0].value mail = row[1].value # 2.編寫郵件內容 content = f''' <h4>{name},你好</h4> <p>請查收你在2025年 5月1日 - 5月31 日的工資</p> <table border='1px solid black'> {thead} {tbody} </table> '''
# 發送郵件 class Test: def ck_log(self): pass def send_email(self, econtent, ename, mail): host = 'smtp.qq.com' user = '你的郵箱' password = '你的授權碼' receivers = [mail] subject = '員工工資表' msg = MIMEText(econtent, 'html', 'utf-8') msg['From'] = Header('有限公司') 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("郵件發送成功!") except smtplib.SMTPException as e: print("Error: 無法發送郵件") print(e)
from openpyxl import load_workbook import smtplib from email.mime.text import MIMEText from email.header import Header ''' 1.獲取excel表的數據 2.編寫郵件內容 3.發送郵件 ''' # 發送郵件 class Test: def ck_log(self): pass def send_email(self, econtent, ename, mail): host = 'smtp.qq.com' user = '1479898695@qq.com' password = 'bijoplffwqqlbaci' receivers = [mail] subject = '員工工資表' msg = MIMEText(econtent, 'html', 'utf-8') msg['From'] = Header('有限公司') 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("郵件發送成功!") except smtplib.SMTPException as e: print("Error: 無法發送郵件") print(e) if __name__ == '__main__': wb = load_workbook('數據表.xlsx') o = Test() cnt = 0 sheet = wb.active thead = '<thead>' # 1.獲取excel表的數據 for row in sheet: tbody = '<tr>' cnt += 1 if cnt == 1: for cell in row: thead += f'<th>{cell.value}</th>' thead += '</thead>' else: for cell in row: tbody += f'<td>{cell.value}</td>' tbody += '</tr>' name = row[0].value mail = row[1].value # 2.編寫郵件內容 content = f''' <h4>{name},你好</h4> <p>請查收你在2025年 5月1日 - 5月31 日的工資</p> <table border='1px solid black'> {thead} {tbody} </table> ''' # 3.發送郵件 if cnt == 3: print('content:', content) print(name, mail) o.send_email(content, name, mail)
關于如何使用Python郵箱自動群發工資條就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。