首页 > 代码库 > 发邮件

发邮件

 

 

 

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(‘发送失败‘)

 

发邮件