# -*- coding: UTF-8 -*- # 作者:老chun的测开之路 # 时间:2023/5/28-9:42 import smtplib import time import pandas as pd from email.header import Header from email.mime.text import MIMEText """ QQ邮箱发邮件 """ def send_mails_QQsmtp(from_mail, to_mail, note_content, apartment_name, subject, user_name, mail_host, mail_port, mymail_user, mymail_pwd): print(f'正在向{to_mail}发生邮件......') # mail msg 设置 msg = MIMEText(note_content, 'plain', 'utf-8') msg['From'] = Header(apartment_name, 'utf-8') msg['To'] = Header(user_name, 'utf-8') msg['Subject'] = Header(subject, 'utf-8') with smtplib.SMTP_SSL(mail_host, mail_port) as smtObj: # 登陆发件人邮箱(公寓财务处邮箱) smtObj.login(mymail_user, mymail_pwd) # 发送 smtObj.sendmail(from_mail, to_mail, msg.as_string()) print('邮件成功发送!') """ 从Excel读取未缴费的用户信息,并封装返回用户信息 例如:[['**********@163.com', '小张', 509, '未缴费'], ['**********@qq.com', '二王', 511, '未缴费']] """ if __name__ == '__main__': """读取Excel""" # user_infos = get_excelInfo('C:\\Users\\weixiangxiang\\Desktop\\公寓用户缴费名单202108.xlsx') # print(user_infos) """公寓信息""" apartment_dict = { 'from_mail': '**********@qq.com', # 密码pwd 'pwd': '**********', 'sub': '公寓用户月份缴费通知提醒', 'apartment_name': '公寓财务处' } """查询用户信息发送邮件""" # for user_info in user_infos: # 使用邮件服务商提供的SMTP服务,需要设置服务器/端口号/用户名/口令(即授权码)等 QQmail_host, QQmail_port = 'smtp.qq.com', 465 QQmail_user = apartment_dict.get('from_mail') QQmail_pwd = apartment_dict.get('pwd') apartment_name = apartment_dict.get('apartment_name') sub = apartment_dict.get('sub') to_mail ='**********@qq.com' # 收件邮箱 user_name = '**********@qq.com' # 亲爱的xxx用户 room_no = '302' # 房间号 note_content = f'亲爱的chunxiangjie,你好:系统显示,您所在的房间号亲爱的chunxiangjie还没有及时缴纳8月份的房租,收到邮件通知后,请及时缴纳,谢谢配合!\ \n亲爱的chunxiangjie\ \n{time.strftime("%Y-%m-%d %H:%M", time.localtime())}' send_mails_QQsmtp(QQmail_user, to_mail, note_content, apartment_name, sub, user_name, QQmail_host, QQmail_port, QQmail_user, QQmail_pwd)
发送邮件功能-随便记录点
最新推荐文章于 2024-06-03 13:31:43 发布