Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. def main(lim_msg):
  2. count = 1
  3. count_error = 0
  4. with codecs.open(DATA_E, 'r', encoding='utf-8', errors='ignore') as f:
  5. for mail in f:
  6. try:
  7. if count > lim_msg:
  8. write_file(NEW_DATA, mail)
  9. print('Recorded emails {}'.format(count))
  10. elif count <= lim_msg:
  11. send_email(SUBJECT, TEXT, mail, FILE_ATTACH)
  12. print('Send letters {}. Last email - {}'.format(count, mail), end='')
  13. time.sleep(2)
  14. except smtplib.SMTPRecipientsRefused:
  15. print('**010')
  16. print('Incorrect email: ' + mail, end='')
  17. continue
  18. except smtplib.SMTPDataError:
  19. write_file(NEW_DATA, mail)
  20. print('Over limit msg. Recorded emails {}'.format(count))
  21. continue
  22. except smtplib.SMTPConnectError:
  23. print('**020')
  24. if count_error > NUM_ATTEMPTS:
  25. write_file(NEW_DATA, mail)
  26. print('Over limit msg. Recorded emails {}'.format(count))
  27. elif count_error < NUM_ATTEMPTS:
  28. send_email(SUBJECT, TEXT, mail, FILE_ATTACH)
  29. print('Server busy, try again later')
  30. count_error += 1
  31. continue
  32. except smtplib.SMTPServerDisconnected:
  33. print('**030')
  34. write_file(NEW_DATA, mail)
  35. print('The server disconnected. Recorded emails {}'.format(count))
  36. continue
  37. except smtplib.SMTPAuthenticationError:
  38. print('**040')
  39. write_file(NEW_DATA, mail)
  40. print('Incorrect login or pass. Recorded emails {}'.format(count))
  41. continue
  42. except smtplib.SMTPNotSupportedError:
  43. print('**050')
  44. write_file(NEW_DATA, mail)
  45. print('The command is not supported by server. Recorded email {}'.format(count))
  46. continue
  47. except smtplib.SMTPHeloError:
  48. print('**60')
  49. write_file(NEW_DATA, mail)
  50. print('The server refused HELO msg. Recorded emails {}'.format(count))
  51. continue
  52. except smtplib.SMTPSenderRefused:
  53. print('**70')
  54. write_file(NEW_DATA, mail)
  55. print('Incorrect sender mail. Recorded emails {}'.format(count))
  56. continue
  57.  
  58. count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement