码迷,mamicode.com
首页 > 编程语言 > 详细

python email 邮件

时间:2019-10-11 14:04:04      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:connect   sendmail   class   tps   color   int   str   main   nec   

.

.

.参考: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 邮件

标签:connect   sendmail   class   tps   color   int   str   main   nec   

原文地址:https://www.cnblogs.com/lshan/p/11653762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!