import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddrmy_sender = 'xxxxxx@163.com' # 发件人邮箱账号my_pass = 'xxxxxx' # 发件人邮箱密码my_user = 'xxxxxx@qq.com' # 收件人邮箱账号,我这边发送给自己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() # 关闭连接复制代码