I’m trying to import emails from my outlook into python. I’m fairly new to python and after reading a few articles it looks like using IMAP is the best solution for this.
My only concern is using my email password for this. The articles I’ve read have all suggested not hard coding passwords, one video I watched suggested using the input()
function in python and then when you run the code in Jupyter Notebook it opens an input field which you can then type your password in and it will use the input into this field as the variable for the password (see code/screenshots below).
My concern is around the fact that it shows and keeps showing the password in jupyter notebook which obviously isn’t very secure. So my questions are:
Is the
input()
method the best to use in this case and is there a way of hashing the password as it’s entered (like you normally would see when logging in to most things) and hiding the input field once the password has been entered (I’ve seen there is the option ofgetpass.getpass()
in this article (Getting a hidden password input) but it mentioned you need to use a proper terminal for this and I’m not sure what that means, is Jupyter Notebook a proper terminal?)How secure is this method in general? Is there a way of anyone seeing the password I’m entering (assuming I can resolve question 1 above), does python save the password anywhere that someone might be able to access later on, because jupyter notebook is done through the browser is there any way of anyone external accessing the code and password?
Below is some example code that I’m using:
import imaplib
import email
imap_server = 'outlook.office365.com'
email_address = 'thomas.chamberlain@mycompany.com'
password = input('enter your password')
imap = imaplib.IMAP4_SSL(imap_server)
imap.login(email_address,password)
imap.selectfolder('Inbox')
and the screenshot below shows what happens when I put in a password (note there's a error because I'm not putting my actual password in and the email isn't my actual email):
I’m fairly new to a lot of this so apologies if I’m asking obvious questions or not giving enough details.
Just for context I’m importing emails from outlook into python so that I can then put the details of the email into some sort of database as we currently don’t have a database of this kind e.g. if an email looked like the below:
Then I'd want something like this to be captured in a table: