70 lines
2.7 KiB
Python
Executable File
70 lines
2.7 KiB
Python
Executable File
from concurrent.futures.thread import ThreadPoolExecutor
|
|
|
|
from imapclient import IMAPClient
|
|
|
|
from src.db.mongo_manager import MONGO_STORE_MANAGER
|
|
from src.mail.mail_constants import create_imap
|
|
from src.pojo.mail.mail_pojo import MailAddress
|
|
from src.utils.excel_reader import ExcelHelper
|
|
|
|
|
|
class MailAddressValidator():
|
|
def __init__(self, login, password):
|
|
self.login = login
|
|
self.password = password
|
|
|
|
def is_valid_email_address(self) -> bool:
|
|
# authenticate
|
|
imap = create_imap(self.login)
|
|
isImapClient = isinstance(imap, IMAPClient)
|
|
isValid = True
|
|
try:
|
|
if isImapClient:
|
|
dat = imap.login(self.login, str(self.password))
|
|
print("dat is " + str(dat) + "for:" + self.login)
|
|
else:
|
|
type, dat = imap.login(self.login, str(self.password))
|
|
print("type is " + str(type) + "for:" + self.login)
|
|
imap.logout()
|
|
except Exception as error:
|
|
print(error)
|
|
isValid = False
|
|
|
|
return isValid
|
|
|
|
def check_and_save_to_db(self):
|
|
if not self.is_valid_email_address():
|
|
MONGO_STORE_MANAGER.insert_invalid_mail(MailAddress(self.login, self.password))
|
|
print("{} is not valid".format(self.login))
|
|
|
|
|
|
def remove_invalid_email():
|
|
invalid = MONGO_STORE_MANAGER.get_invalid_emails()
|
|
for mail in invalid:
|
|
MONGO_STORE_MANAGER.remove_email_from_destination_email_list(mail)
|
|
|
|
|
|
def find_and_update_invalid_emails(mail_list):
|
|
# mail_address1 = MailAddress(mail="perrateke1983@onet.pl", password="8EQh#UuyMx8zVO9")
|
|
# # mail_address2 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
|
|
# # mail_address2 = MailAddress(mail="sdfgfhgf1986@aol.com", password="fjwcgvhxxlywqfwm")
|
|
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
|
|
# # mail_address4 = MailAddress(mail="hongjiang176@aol.com", password="ftzpscgzvwneelmn")
|
|
# mail_address4 = MailAddress(mail="ryan_meacham2856@yahoo.com", password="ulgggkodxqbvrpgm")
|
|
# mail_list = [mail_address3, mail_address2, mail_address1, mail_address4]
|
|
# mail_list = [mail_address1]
|
|
with ThreadPoolExecutor(max_workers=200) as executor:
|
|
for mail in mail_list:
|
|
valiator = MailAddressValidator(mail.mail, mail.password)
|
|
executor.submit(valiator.check_and_save_to_db)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
remove_invalid_email()
|
|
|
|
# mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
|
# excel_reader = ExcelHelper()
|
|
# mail_list = excel_reader.read_mails_and_pwd(file_name="/Users/lpan/Downloads/hotmail_list.xlsx")
|
|
# print(email_list)
|
|
# find_and_update_invalid_emails(mail_list)
|