阿-_-涵的博客
#首先写一个模块功能,发邮件功能打包起来 from smtplib import SMTP from email.mime.text import MIMEText def send_email(SMTP_host, from_addr, password, to_addrs, subject=‘‘, content=‘‘): email_client = SMTP(host=SMTP_host) email_client.login(from_addr, password) # create msg msg = MIMEText(content, _charset=‘utf-8‘) msg[‘Subject‘] = subject email_client.sendmail(from_addr, to_addrs, msg.as_string()) email_client.quit()
# -*- coding: cp936 -*- from my_email import send_email if __name__ == ‘__main__‘: try: send_email(‘smtp.163.com‘, ‘[email protected]‘, ‘xxxx‘, ‘[email protected]‘, ‘邮件标题‘, ‘邮件内容‘) print("发送成功") except Exception as e: print(e)
时间: 2024-11-08 00:54:27