Skip to content

Instantly share code, notes, and snippets.

@bensoer
Created January 2, 2019 21:53
Show Gist options
  • Save bensoer/814e3bf2256261fa7933123f51464e82 to your computer and use it in GitHub Desktop.
Save bensoer/814e3bf2256261fa7933123f51464e82 to your computer and use it in GitHub Desktop.
POP and IMAP for automated message retrieval
import poplib
import ssl
from imaplib import IMAP4_SSL
pop3_server = "server"
pop3_username = "username"
pop3_password = "password"
imap_server = "server"
#pop3_server = "server"
#pop3_username = "username"
#pop3_password = "password"
if __name__ == '__main__':
print("Starting PopDropNRoll")
print(ssl.OPENSSL_VERSION)
print("Connecting To The Server (" + pop3_server + ")")
ctx = ssl.create_default_context()
#ctx.options &= ~ssl.OP_NO_SSLv3
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
try:
server = poplib.POP3_SSL(host=pop3_server, port=995, timeout=120)
print("Authenticating")
server.user(pop3_username)
server.pass_(pop3_password)
print("Fetching Messages")
resp, items, octets = server.list()
except ssl.SSLError as error:
print(error)
except poplib.error_proto as detail:
print(detail)
#server = IMAP4_SSL(imap_server, port=993, ssl_context=ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment