def email(): import smtplib from email.mime.text import MIMEText from email.utils import formataddr ret = True try: msg = MIMEText(‘邮件内容‘,‘plain‘,‘utf-8‘) msg[‘From‘] = formataddr([‘zhou‘,‘发件邮箱帐号‘]) msg[‘To‘] = formataddr([‘zzm‘,‘8400033‘]) msg[‘Subject‘] = ‘主题‘ server = smtplib.SMTP(‘smtp.163.com‘,25) server.login(‘发件邮箱帐号‘,‘发件邮箱密码‘) server.sendmail(‘发件邮箱帐号‘,[‘收件邮箱帐号‘],msg.as_string()) server.quit() except: ret = False return ret email()if ret: print(‘发送成功‘)else: print(‘发送失败‘)
时间: 2024-10-03 13:39:58