使用163smtp发送邮件
import smtplib from email.mime.text import MIMEText mail_host = 'smtp.163.com' mail_user = '发件人邮箱' mail_pwd = '授权码' sender = '发件人邮箱' receivers = ['收件人邮箱'] content = 'python使用163smtp发送邮件' title = '人生苦短' def sendmail(): message = MIMEText(content, 'plain', 'utf-8') # 内容,格式,编码 message['From'] = "{}".format(sender) message['To'] = ','.join(receivers) message['Subject'] = title try: smtpobj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信,端口一般是465 smtpobj.login(mail_user, mail_pwd) # 登陆验证 smtpobj.sendmail(sender, receivers, message.as_string()) print('mail has been send successfully') except Exception as e: print(e) sendmail()