0

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:

  1. 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 of getpass.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?)

  2. 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):

example of jupyter notebook where I enter a password into an input field

and the password is still visible once running the code

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:

example of email that I'd want to collect data from

Then I'd want something like this to be captured in a table:

Example of data I'd like to capture

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
Thomas Chamberlain
  • 127
  • 2
  • 2
  • 8
  • Did you try using `getpass.getpass()`? Did it work? – Barmar Mar 28 '23 at 16:18
  • I didn't try ```getpass.getpass()``` just because in the this article (https://stackoverflow.com/questions/9202224/getting-a-hidden-password-input) it mentioned that it "requires a proper terminal" and I didn't know what that meant and whether Jupyter Notebooks was a proper terminal – Thomas Chamberlain Mar 29 '23 at 08:39
  • You would find out by trying. – Barmar Mar 29 '23 at 14:15

0 Answers0