• python3实现发送邮件代码


    前言:

           刚学习python ,简单的代码学习下 就是实现发送邮件的代码。如下:

    # -*- coding:utf-8 -*-
    
    # **********************************
    # ** http://weibo.com/lixiaodaoaaa #
    # ****** by:lixiaodaoaaa ***********
    
    def sendEmail(mailAddress, mailText):
        import smtplib
        from email.mime.text import MIMEText
        from email.utils import formataddr
    
        msg = MIMEText(mailText, 'plain', 'utf-8')
        msg['From'] = formataddr(["Dog", 'lixiaodaoaaa@126.com'])
        msg['To'] = formataddr([mailText, mailAddress])
        msg['Subject'] = "主题"
        try:
            server = smtplib.SMTP("smtp.126.com", 25)
            server.login("lixiaodaoaaa@126.com", "DogYouXiangPassword")
            server.sendmail('lixiaodaoaaa@126.com', [mailAddress], msg.as_string())
            server.quit()
            return True
        except:
            return False
    
    
    userInputEmailAdd = input("请输入你要发送的邮件地址:  ")
    userInputEmailContent = input("请输入你想说的话:  ")
    if sendEmail(userInputEmailAdd, userInputEmailContent):
        print("发送成功")
    else:
        print("发送失败。。。。。")
    
  • 相关阅读:
    题解45 跳跃游戏 II
    《重构》第八章阅读总结
    Scala学习笔记一
    Java初学随笔
    染色算法总结
    BingMap
    Google Earth API 替换方案
    本周安排
    OleDb 内存泄露问题
    css3 布局
  • 原文地址:https://www.cnblogs.com/lixiaodaoaaa/p/6659908.html
Copyright © 2020-2023  润新知