0

I'm working on a very simple imap client for windows cmd. Its work will be to search for messages with specific form: address and print the body to stdout.

OpenSSL is installed from here and and directory exist in PATH

Note: This script works well on Linux.

Edit: Already tried this solution. It doesn't work.

The problem is that it throws this exception for openssl:

Traceback (most recent call last):
  File "simplemailclient.py", line 21, in <module>
    context = imapclient.create_default_context()
  File "C:\Python27\lib\site-packages\imapclient\tls.py", line 109, in create_de
fault_context
    context.load_verify_locations(cadata=certs)
  File "C:\Python27\lib\site-packages\backports\ssl\core.py", line 654, in load_
verify_locations
    self._ctx.load_verify_locations(cafile, capath)
  File "C:\Python27\lib\site-packages\OpenSSL\SSL.py", line 533, in load_verify_
locations
    _raise_current_error()
  File "C:\Python27\lib\site-packages\OpenSSL\_util.py", line 48, in exception_f
rom_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: []

Here's my code:

import email
import imapclient
import sys
from backports import ssl


HOST = sys.argv[1]
USERNAME = sys.argv[2]
PASSWORD = sys.argv[3]

context = imapclient.create_default_context()
context.check_hostname = False
context.verify_mode = 0


server = imapclient.IMAPClient(HOST, use_uid=True, ssl=True, ssl_context=context)
server.login(USERNAME, PASSWORD)
select_info = server.select_folder('INBOX')

messages = server.search([u'FROM','user@example.net'])

response = server.fetch(messages, ['RFC822'])

for msgid, data in response.iteritems():
        messageString= data['RFC822']
        msgStringParsed = email.message_from_string(messageString)
        for part in msgStringParsed.walk():
            if part.get_content_type() == "text/plain":
                print part.get_payload()
                exit(0)
            pass
Community
  • 1
  • 1
specktator
  • 95
  • 1
  • 8
  • Nope. Already seen it. The answer doesn't solve the problem. – specktator Aug 07 '16 at 15:59
  • It would be very useful to include what you've tried (even if failed) to your question (and not later in a comment) to avoid such "possible duplicate" and to make it easier for others to help you. Remember: nobody is required to help you and the easier you make it for others the more likely you will get help. – Steffen Ullrich Aug 07 '16 at 16:03
  • That's my bad. I'm sorry for that. I will edit the post. – specktator Aug 07 '16 at 16:06

0 Answers0