发送邮件功能-随便记录点

# -*- 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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值