python 发gmail 邮件

原创
2023/10/30 20:53
阅读数 78

gmail 有个认证的流程

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.header import Header

mail_host="smtp.gmail.com"  #设置服务器
mail_user="shuai.shi@shopee.com"    #用户名
mail_pass=""   #口令 这个口令从gmail 二次认证里面添加


sender = 'shuai.shi@shopee.com'
receivers = ['shuai.shi@shopee.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('Python llllllllllllllllllllllll...', 'plain', 'utf-8')
message['From'] = Header("shishuai%%%%%", 'utf-8')
message['To'] =  Header("ssss", 'utf-8')

subject = 'Python SMTP this is a test '
message['Subject'] = Header(subject, 'utf-8')


smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 587)    # 25 为 SMTP 端口号
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部