import smtplib from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText """ 发送普通邮件 """ # 创建邮件主体对象 email = MIMEMultipart() # 设置发件人、收件人和主题 email['From'] = '发件人邮箱' email['To'] = '收件人邮箱' email['Subject'] = Header('你好,cp', 'utf-8') # 添加邮件正文内容 content = """你好,cp""" email.attach(MIMEText(content, 'plain', 'utf-8')) # 创建SMTP_SSL对象(连接邮件服务器) smtp_obj = smtplib.SMTP_SSL('smtp.163.com', 465) # 通过用户名和授权码进行登录 smtp_obj.login('发件人邮箱', '授权码') # 发送邮件(发件人、收件人、邮件内容(字符串)) smtp_obj.sendmail( '发件人邮箱', '收件人邮箱', email.as_string() )
标签:收件人,python,发送,发件人,import,邮箱,email,邮件 From: https://www.cnblogs.com/ashuai123/p/17455458.html