zoukankan      html  css  js  c++  java
  • python实战===使用smtp发送邮件的源代码,解决554错误码的问题,更新版!

    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
    import time
    #密文输入密码
    from getpass import getpass
    
    
    def email():
        try:
            #这两个参数必须要,不然就会出现554的错误,不然少参数
            msg['from']=sender
            msg['to']=receiver
            #连接发送邮箱
            smtp = smtplib.SMTP()
            smtp.connect(smtpserver)
            smtp.login(user,password)
            smtp.sendmail(sender, receiver, msg.as_string())
            smtp.quit()
            print("",i,"次发送,成功!")
            time.sleep(2)
        except:
            print("",i,"次发送,失败!")
            time.sleep(2)
            
    
    #发送邮箱服务器
    smtpserver = "smtp.163.com"
    #发送邮箱的账号/密码
    user= input("请输入你的163邮箱账号:")
    #password=input("请输入密码:")
    #以密文的方式输入
    password=getpass("请输入你的密码:")
    #发送邮箱
    sender=user
    #收件箱
    receiver =input("请输入收件人邮箱:")
    #发送主题
    subject = input("请输入邮件的主题:")
    #编写HTML类型的邮件正文
    zw=str(input("请输入邮件内容:"))
    msg = MIMEText(zw,"plain","utf-8")
    msg['Subject'] = Header(subject, 'utf-8')
    
    while True:
        try:
            n=input("请输入发送次数")
            n=int(n)
            break
        except:
            print("请输入你要发送的次数,必须是正整数~")          
        
    i=1
    while i<=n:
        email()
        i +=1
    print("执行完毕")
  • 相关阅读:
    c# 中textbox 换行符是什么??
    aspnetpager注意事项
    asp 自动弹出窗口
    用递归方法删除文件夹目录及文件
    二维数组的应用
    外边框的样式
    JS 不间断滚动
    单目标 JADE
    在Delphi中使用Action降低水平功能和业务功能的耦合
    关于TListView中的Data属性
  • 原文地址:https://www.cnblogs.com/botoo/p/7269221.html
Copyright © 2011-2022 走看看