How to Create a New Folder in a Gmail Account with Python
In this article, we show how to create a new folder in a gmail email account with Python.
So, in order to create a new folder in a gmail account, we first must gain access to IMAP and authenticate into the email account.
IMAP stands for Internet Message Access Protocol.
IMAP is a protocol that allows a user to gain access into an email account in order to view incoming email, folders, or create a new folder.
In contrast, SMTP is a protocol that allows a user to gain access into an email account in order to send out email to other people.
So, IMAP is a protocol to view and manipulate contents of an email account, while SMTP is a protocol to send out outgoing email.
In order to create a new folder in a gmail account with Python, you need to access IMAP and authenticate into the email account.
So, below is the code in order to access IMAP, authenticate into an email account,
and create a new folder within the email account.
So, let's go over the code now shown above.
First, we must import the email and imaplib modules.
We then have to specify the IMAP that we want to gain access to, which is gmail. The hosting name for gmail's IMAP is "imap.gmail.com"
We then create a username and password of the gmail account that you are accessing.
Then all you have to do after this to create a new folder in the gmail email account is, mail.create("BusinessEmails")
This will create the new folder, BusinessEmails, in the gmail email account.
So, this is just a quick way to create new folders in an email account with Python,
specifically in this case with gmail.
Related Resources
How to Randomly Select From or Shuffle a List in Python