標籤:\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帳號發送郵件