python uses a random 163 account to send emails

import linecache
import smtplib
import time
import linecache
import random


# Calculate the number of lines in txt, in 163 account_2.txt, each line stores an account password! 

txt = open(r ' F:\163 account_2.txt ' , ' r ' )  
data = txt.read()  
txt.close()  
n = data.count( ' \n ' )
 print ( " Total number of rows " ,n)
 #Select a random number 
i = random.randint(1, (n+1 ))
 print ( " Number of rows used this time " , i)
 print ( " ============================ " )
 # ##Get the data of the corresponding i line 
line=linecache.getline( r ' F:\163 account_2.txt ' ,i)
 #Slice realizes separation of account and password 
user = line.split( " ---- " ) [0]
password = line.split("----")[1].replace('\n','')
print(user)
print(password)

try :
     #Sending email account/password 
    smtpserver = " smtp.163.com " 
    smtp = smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(user,password)
    print ( " Email login is successful! " )
     print ( " No. " ,(i-1), " Line account is valid " )
    time.sleep( 1 )
 except :
     print ( " Email login failed, please re-enter! " )
            
    time.sleep(1)

In this way, although the login of 163 mailboxes can be achieved, the ip may be locked.

Note that the account document is uploading the file: 163account_2.rar

The source code of python using smtp to send mail, to solve the problem of 554 error code, updated version!

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("执行完毕")

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325149748&siteId=291194637