# -*- coding:utf-8 -*- import smtplib # 设置发件人邮箱和密码 sender_email = 'XXXXXX' sender_password = 'XXXXXX' # 设置授权码 access_token = 'XXXXXX' # 设置收件人邮箱 receiver_email = 'XXXXXX' # 设置邮件主题和内容 subject = 'XXXXXX' # subject通过位置参数传入 # subject = sys.argv[1] body = 'XXXXXX' # body通过位置参数传入 # body = sys.argv[2] # 创建SMTP客户端对象 # 加密端口号为465 server = smtplib.SMTP_SSL('smtp.ym.163.com', 465) server.login(sender_email, sender_password) # 发送邮件 msg = f'Subject: {subject}\n\n{body}' print(msg) try: server.sendmail(sender_email, receiver_email, msg) except Exception as e: print(e) print('发送邮件失败') else: print('发送邮件成功') # 关闭SMTP客户端连接 server.quit()
06-09
1381
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-31
683
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-27
1196
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)