python使用隨機的163帳號發送郵件

來源:互聯網
上載者:User

標籤:\n   出現   line   主題   失敗   except   port   password   使用   

import linecacheimport smtplibimport timeimport linecacheimport random#算出txt的行數,163帳號_2.txt中,每一行都儲存一個帳號密碼!txt = open(r‘F:\163帳號_2.txt‘,‘r‘)  data = txt.read()  txt.close()  n = data.count(‘\n‘)print("總行數",n)#選取隨機的數i = random.randint(1, (n+1))print("本次使用的行數",i)print("===========================")###得到對應的i行的資料line=linecache.getline(r‘F:\163帳號_2.txt‘,i)#切片實現分離出帳號和密碼user = line.split("----")[0]password = line.split("----")[1].replace(‘\n‘,‘‘)print(user)print(password)try:    #發送郵箱的帳號/密碼    smtpserver = "smtp.163.com"    smtp = smtplib.SMTP()    smtp.connect(smtpserver)    smtp.login(user,password)    print("郵箱登陸成功!")    print("第",(i-1),"行帳號有效")    time.sleep(1)except:    print("郵箱登陸失敗,請重新輸入!")                time.sleep(1)

這樣雖然可以實現163郵箱的登入,但是可能會被鎖定ip

備忘帳號文檔在上傳的檔案:163帳號_2.rar

python使用smtp發送郵件的原始碼,解決554錯誤碼的問題,更新版!

import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerimport time#密文輸入密碼from getpass import getpassdef 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=1while i<=n:    email()    i +=1print("執行完畢")

 

python使用隨機的163帳號發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.