Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from imaplib import IMAP4_SSL
- YA_HOST = "imap.yandex.ru"
- YA_PORT = 993
- YA_USER = "LOGIN"
- YA_PASSWORD = "PASSWROD"
- SENDER = "Yoba"
- connection = IMAP4_SSL(host=YA_HOST, port=YA_PORT)
- connection.login(user=YA_USER, password=YA_PASSWORD)
- status, msgs = connection.select('INBOX')
- assert status == 'OK'
- typ, data = connection.search(None, 'FROM', '"%s"' %s SENDER)
- print(data)
- for num in data[0].split():
- typ, message_data= connection.fetch(num, '(RFC822)')
- print(data)
- print('Message %sn%sn' % (num, message_data[0][1]))
- connection.close()
- connection.logout()
- >>> [b'1757 1758 1759 1760 1774 1775']
- mail = email.message_from_bytes(message_data[0][1])
- if mail.is_multipart():
- for part in mail.walk():
- content_type = part.get_content_type()
- filename = part.get_filename()
- if filename:
- # Нам плохого не надо, в письме может быть всякое барахло
- with open(part.get_filename(), 'wb') as new_file:
- new_file.write(part.get_payload(decode=True))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement