zoukankan      html  css  js  c++  java
  • python 之邮件发送

    • 发送邮件脚本
    import smtplib
    from email.mime.text import MIMEText
    
    
    def SendMail():
        mail_host = "smtp.163.com" #邮箱服务
        mail_user = "xxx@163.com" #发件人邮箱
        mail_pass = "xxx" # 开启的密码,smtp
    
        sender = "xxx@163.com" #发件人邮箱
        receuvers = ['xxxx@163.com'] #收件人邮箱
    
        content = "Python Send Mail!"
        title = "Python SMTP Mail Test"
    
        data = {
            "title": title,
            "content": content
        }
    
        #信息拼接
        message = MIMEText(data['content'],'Plain', "utf-8")
        message['From'] = "{}".format(sender)
        message['To'] = ",".join(receuvers)
        message['Subject'] = data['title']
       
        try:
            smtpObj = smtplib.SMTP_SSL(mail_host, 465) #加密
            smtpObj.login(mail_user,mail_pass)  # 登录
            smtpObj.sendmail(sender,receuvers,message.as_string()) # 发送邮件
            print("mail has been send successfully")
        except smtplib.SMTPException as e:
            print(e)
    
    if __name__ == '__main__':
        SendMail()
    
  • 相关阅读:
    洛谷[P1002]过河卒
    ACM-Teleportation
    ACM-Team Tic Tac Toe
    Data_Structure04-树
    Data_Structure03-栈和队列
    Data_Structure02-线性表
    Data_Structure01-绪论
    C语言第二次实验报告
    C语言第一次实验报告
    mysql
  • 原文地址:https://www.cnblogs.com/zoulixiang/p/14292884.html
Copyright © 2011-2022 走看看