First Week Homework: Email Sending/Checking with Python & Node.js

For our first week of Internet of Things we are working on accessing remote data with python and node.js. In order to better understand how this works, we were tasked with connecting with our own email account and both sending/checking email.

Below are the projects I made. You can find the code on my GitHub.

Email Send:

A Story About a Cat Named…

Welcome to Cat Story Generator!

  • Pick a friend’s Email You Want to Send To
  • Write your Friend’s Name
  • Pick a number Between 1 and 5
  • Answers a corresponding follow-up question based on number you select

Cat Story Generator then takes the inputted info and creates a short story based on your responses, attaching a related moving (PNG?) of the corresponding image to go with the story. PS: I didn’t know PNGs could be animated, but apparently they can in Gmail!

If the user inputs a number not between 1 and 5 or anything else, a random Cat story is generated for them.

Please note this will not work out of the box. I created a separate config file to hold a username and password, and purposely ****** them out for this. If you want this to work, go to and change the email and password to one that is yours.

I used the SMTP library reference at to help figure out the images

Cat Images from:

Email Check:

For this project, I built a node.js program that takes user input allowing users to select which mailbox they want to view: Sent, Starred, Important, Drafts, or Inbox by selecting 1-5. It then used the “prompt” module to allow them to select a range of email they want to view: 1 being the newest and the second number being the oldest (so 1 and 5 would show the first 5 newest emails, 10 – 15 would show the 10th oldest – the 15th oldest. It then fetches the date, from, and to of the email and prints to terminal. I used a tutorial from IMAP library on GitHub by Mscdex from to start and modified it

This python script uses the IMAP protocol to fetch a user’s most recent message from Gmail. It allows the user to select whether they want to check the Inbox, Sent Mail, or Drafts and then asks if they only want to see unseen mail, or if they want to see all mail. It also uses the Email library to clean up the message and fetch the body of the email and convert it to plaintext. It also returns how many email messages there are in that particular folder. Like the sendEmail program, it sources the username and password from a separate config file. I used a walkthrough of the IMAP library for Python at for reference and modified.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.