Video Tutorial
Watch first if you want to see the full Raspberry Pi Pico W email setup using Gmail and an app password.
Project Overview
In this tutorial, you will use a Raspberry Pi Pico W with Gmail (SMTP via app password) to send an email from MicroPython. This is useful for remote monitoring, alerts, communication between devices, and periodic reporting.
- Time: 15 to 30 minutes
- Skill level: Beginner
- What you will build: A MicroPython script that connects the Pico W to Wi-Fi and sends an email through Gmail SMTP
Parts List
From ShillehTek
- Raspberry Pi Pico 2W - the WiFi microcontroller board used in this build
External
- Gmail account with Two Factor Authentication enabled
- Gmail App Password (generated after enabling 2FA)
- umail.py library (copy into the Pico filesystem)
- MicroPython environment for the Pico W (plus a way to copy files to the board)
- Wi-Fi network credentials (SSID and password)
Note: This tutorial uses a Gmail app password (not your normal Gmail password) for SMTP authentication in MicroPython.
Step-by-Step Guide
Step 1 - Enable Two Factor Authentication in Gmail
Goal: Enable 2FA on the Gmail account you will use for SMTP.
What to do: Open your Google account security settings and enable two-factor authentication for the Gmail account you will use.
https://myaccount.google.com/security
After setup, your security page should show that 2-step verification is turned on.
Expected result: Two Factor Authentication is enabled on the Gmail account.
Step 2 - Generate a Gmail App Password
Goal: Create an app password to use in MicroPython for SMTP login.
What to do: In the same Google account security area, open App Passwords and generate a new app password. The selected device type does not need to match your exact setup.
https://myaccount.google.com/security
The app password will replace your normal Gmail password for authentication in MicroPython.
Expected result: You have a generated app password ready to paste into your script.
Step 3 - Add umail.py to your Pico W filesystem
Goal: Install the MicroPython email library used by the script.
What to do: Get umail.py and copy its contents into a file named umail.py. Save it in the top-most directory on the Pico W filesystem.
Expected result: umail.py exists on the Pico W so it can be imported by your script.
Step 4 - Use the email script template (MicroPython)
Goal: Connect the Pico W to Wi-Fi and send an email using Gmail SMTP over SSL.
What to do: Copy the following script and replace the placeholder values (email, name, app password, recipient, and Wi-Fi credentials). The script connects to Wi-Fi first, then sends an email using an SMTP object.
Code:
import network
import time
import urequests
import umail
# Internal libs
import constants
# Email details
sender_email = <Your email>
sender_name = <Your name>
sender_app_password = <APP_PASSWORD>
recipient_email = <EMAIL>
email_subject ='Like, Comment, Subscribe'
def connect_to_internet(ssid, password):
# Pass in string arguments for ssid and password
# Just making our internet connection
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
print(wlan.status())
raise RuntimeError('network connection failed')
else:
print('connected')
print(wlan.status())
status = wlan.ifconfig()
connect_to_internet(<INTERNET_NAME>, <INTERNET_PASSWORD>)
# Send the email
# Connect to the Gmail's SSL port
smtp = umail.SMTP('smtp.gmail.com', 465, ssl=True)
# Login to the email account using the app password
smtp.login(sender_email, sender_app_password)
# Specify the recipient email address
smtp.to(recipient_email)
# Write the email header
smtp.write("From:" + sender_name + "<"+ sender_email+">\n")
smtp.write("Subject:" + email_subject + "\n")
# Write the body of the email
smtp.write("Test Email from Raspberry Pi Pico W")
# Send the email
smtp.send()
# Quit the email session
smtp.quit()
print('Email Sent')
Expected result: After you plug in your variables and run the script, the Pico W connects to Wi-Fi and the console prints Email Sent.
Conclusion
You set up a Raspberry Pi Pico W to send an email through Gmail by enabling 2FA, generating an app password, adding umail.py, and running a MicroPython SMTP script. This approach is useful for simple notifications, alerts, and lightweight reporting from your Pico W.
Want the exact parts used in this build? Grab what you need from ShillehTek.com. If you want help customizing this project or building something similar for your setup, check out our IoT consulting services. Do not forget to like, comment, or subscribe to the channel for more useful information!


