python email 邮件
Posted lshan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python email 邮件相关的知识,希望对你有一定的参考价值。
.
.
.参考:https://www.runoob.com/python3/python3-smtp.html
#encoding=utf-8 ‘‘‘ Created on 2019年10月11日 @author: sea ‘‘‘ import smtplib from email.mime.text import MIMEText from email.header import Header def send(From,to,subject,content): ‘‘‘ send(From,to,subject,content) ‘‘‘ sendMsg(to,subject,content,From) def sendTo(to,subject,content): ‘‘‘sendTo(to,subject,content)‘‘‘ sendMsg(to,subject,content) def sendMsg(To,Subject,Content,From=‘sea@icil.net‘,Host=‘192.168.16.253‘): message = MIMEText(Content, ‘plain/html‘, ‘utf-8‘) message[‘Subject‘] = Header(Subject, ‘utf-8‘) message[‘From‘] = From # 发送者 message[‘To‘] = ‘‘ # 接收者 for receiver in To: message[‘To‘]+=receiver try: ‘‘‘if is 3rd email‘‘‘ # smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号 mail_host ="smtp.XXX.com" #设置服务器 # smtpObj.login(mail_user,mail_pass) //登录用户名,密码 smtpObj = smtplib.SMTP(Host,25) smtpObj.sendmail(From, To, message.as_string()) print ("邮件发送成功") except smtplib.SMTPException: print ("Error: 无法发送邮件") if __name__ == ‘__main__‘: From = ‘SeaSend@icil.net‘ To = [‘sealiu@icil.net‘,"lshan523@163.com"] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 Subject = ‘Python SMTP 邮件测试 hahhahhaahahahah toototoootoot‘ Content="‘Python 邮件发送测试...‘" Host=‘192.168.16.253‘ # send(From, To, Subject, Content) sendTo(To, Subject, Content)
以上是关于python email 邮件的主要内容,如果未能解决你的问题,请参考以下文章