Python3实现邮箱发送

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

my_sender = '[email protected]'  # 发件人邮箱账号
my_pass = 'xxxxxx'  # 发件人邮箱密码
my_user = '[email protected]'  # 收件人邮箱账号,我这边发送给自己
msg = MIMEText('I like you so much.', 'plain', 'utf-8')
msg['From'] = formataddr(["FromTask", my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr(["Crawler", my_user])  # 括号里的对应收件人邮箱昵称、收件人邮箱账号
msg['Subject'] = "miss you"  # 邮件的主题,也可以说是标题

server = smtplib.SMTP_SSL("smtp.163.com", 465)  # 发件人邮箱中的SMTP服务器
server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(my_sender, [my_user, ], msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit()  # 关闭连接
复制代码

转载于:https://juejin.im/post/5d0238b9f265da1b897acb0b

你可能感兴趣的:(Python3实现邮箱发送)