Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main(lim_msg):
- count = 1
- count_error = 0
- with codecs.open(DATA_E, 'r', encoding='utf-8', errors='ignore') as f:
- for mail in f:
- try:
- if count > lim_msg:
- write_file(NEW_DATA, mail)
- print('Recorded emails {}'.format(count))
- elif count <= lim_msg:
- send_email(SUBJECT, TEXT, mail, FILE_ATTACH)
- print('Send letters {}. Last email - {}'.format(count, mail), end='')
- time.sleep(2)
- except smtplib.SMTPRecipientsRefused:
- print('**010')
- print('Incorrect email: ' + mail, end='')
- continue
- except smtplib.SMTPDataError:
- write_file(NEW_DATA, mail)
- print('Over limit msg. Recorded emails {}'.format(count))
- continue
- except smtplib.SMTPConnectError:
- print('**020')
- if count_error > NUM_ATTEMPTS:
- write_file(NEW_DATA, mail)
- print('Over limit msg. Recorded emails {}'.format(count))
- elif count_error < NUM_ATTEMPTS:
- send_email(SUBJECT, TEXT, mail, FILE_ATTACH)
- print('Server busy, try again later')
- count_error += 1
- continue
- except smtplib.SMTPServerDisconnected:
- print('**030')
- write_file(NEW_DATA, mail)
- print('The server disconnected. Recorded emails {}'.format(count))
- continue
- except smtplib.SMTPAuthenticationError:
- print('**040')
- write_file(NEW_DATA, mail)
- print('Incorrect login or pass. Recorded emails {}'.format(count))
- continue
- except smtplib.SMTPNotSupportedError:
- print('**050')
- write_file(NEW_DATA, mail)
- print('The command is not supported by server. Recorded email {}'.format(count))
- continue
- except smtplib.SMTPHeloError:
- print('**60')
- write_file(NEW_DATA, mail)
- print('The server refused HELO msg. Recorded emails {}'.format(count))
- continue
- except smtplib.SMTPSenderRefused:
- print('**70')
- write_file(NEW_DATA, mail)
- print('Incorrect sender mail. Recorded emails {}'.format(count))
- continue
- count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement