0

I am using IMAPClient library for fetching emails. In my application i have multiple options where i have to always create a socket connection or login to email account using IMAPClient.

  1. Read mail
  2. Fetch mail
  3. Fetch folders etc

For each options my application has to create a connection with email account using IMAPClient which consume time. Is there any way where i can only create a connection one time and same connection i can reuse to perform other activities whenever required.

Sample code example

from imapclient import IMAPClient
email_address = "emailid"
password = "password"
imap_server = 'imap.gmail.com'
mail_server = IMAPClient(imap_server, use_uid=True, ssl=True)
mail_server.login(email_address, password)

I want to store this mail_server ssl socket object and reuse whenever needed.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
shashank verma
  • 303
  • 1
  • 3
  • 9
  • Please share your code, or a relevant example, so people can suggest concrete changes. Don't ask StackOverflow to write your code for you. – Grismar Dec 28 '20 at 14:06
  • question edited and code added – shashank verma Dec 28 '20 at 14:08
  • 1
    Other than referencing it with a variable (like you already have) , there's no way to "store" an ssl socket connection. That's like asking how to save a phone conversation, so you can start talking to the person on the other side whenever you like - you'll need to call them again / reconnect to the server. But as long as your script is running, you can use the connection in `mail_server` – Grismar Dec 28 '20 at 14:11

0 Answers0