import smtplib from email.message import EmailMessage email = EmailMessage() email['from'] = 'xxx' email['to'] = 'xxxxx' email['subject'] = '邮件主题' email.set_content("邮件正文") with smtlib.SMTP(host='smtp.gmail.com',port=587)as smtp: ## sending request to server smtp.ehlo() smtp.starttls() smtp.login("email_id","Password") smtp.send_message(email) print("email send success")