python 自动邮件发送 报错smtplib.SMTPServerDisconnected: Connection unexpectedly closed
import smtplib from email.mime.text import MIMEText from email.message import EmailMessage #email = EmailMessage() ## Creating a object for EmailMessage #email['from'] = 'xyz name' ## Person who is sending #email['to'] = 'xyz id' ## Whom we are sending #email['subject'] = 'xyz subject' ## Subject of email #email.set_content("Xyz content of email") ## content of email #with smtplib.SMTP(host='smtp.qq.com',port=465)as smtp: ## sending request to server # smtp.ehlo() ## server object #smtp.starttls() ## used to send data between server and client #smtp.login("email_id","Password") ## login id and password of gmail #smtp.send_message(email) ## Sending email #print("email send") ## Printing success message sender = '1165707116@qq.com' receivers = '1173760256@qq.com' msg = MIMEText('hi im hrz') msg['Subject'] = 'Test mail' msg['From'] = '573434343@qq.com' msg['To'] = '117376024@qq.com' with smtplib.SMTP_SSL('smtp.qq.com') as server: server.login('573434343@qq.com','*******') server.sendmail(sender, receivers, msg.as_string()) print("mail successfully sent")
把
smtplib.SMTP 改成
smtplib.SMTP_SSL('smtp.qq.com')问题得到解决
本文来自博客园,作者:蚌壳里夜有多长,转载请注明原文链接:https://www.cnblogs.com/dbahrz/p/17654351.html