当前位置:首页 > Python教程 > python技巧

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)
    

 

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


【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!