📧 How to Send Emails Like a Pro Using Termux and Python in 2025
Short Snippet: Learn how to send emails using Termux and Python with your Gmail SMTP. This easy guide explains app password setup, email scripting, and sending messages securely — all from your Android phone.
📬 Introduction
Did you know that you can send emails straight from your Android phone using Termux and Python? Whether you're into ethical hacking, automating work, or experimenting with cool projects, this guide helps you create a real email-sending tool using Gmail SMTP!
🧠 What is SMTP?
SMTP stands for Simple Mail Transfer Protocol. It’s how your emails are sent from one server to another over the internet.
- It acts like a postman for emails.
- Used by Gmail, Outlook, Yahoo, etc.
- Allows apps or scripts to send emails securely.
🔐 How to Create a Gmail App Password
To send mail via Gmail SMTP securely, you need to create an app-specific password:
- Go to account.google.com
- Navigate to Security
- Enable 2-Step Verification
- After that, go to App Passwords
- Select:
- App: Mail
- Device: Other (Termux/Python)
- Click Generate
- Copy the 16-digit password shown — this is your app password.
💡 This app password is safer than your Gmail password. You’ll use it only for your script.
📲 Setting Up Termux
Now let’s get Termux ready to send mail.
Step 1: Install Python and Update Termux
pkg update && pkg upgrade
pkg install python
Step 2: Create the Python Script
nano mail.py
Paste the following code:
import smtplib
from email.message import EmailMessage
import getpass
print("\n" + "="*50)
print(" MAIL by kumarsmagic.com")
print("="*50 + "\n")
smtp_server = input("SMTP server (e.g. smtp.gmail.com): ").strip()
smtp_port = int(input("SMTP port (e.g. 587): ").strip())
email_address = input("Your email address: ").strip()
password = getpass.getpass("Your app password: ")
to_email = input("\nRecipient email: ").strip()
subject = input("Subject: ").strip()
body = input("Message body: ").strip()
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = email_address
msg['To'] = to_email
msg.set_content(body + "\n\n-- Sent via kumarsmagic.com mailer")
try:
with smtplib.SMTP(smtp_server, smtp_port) as smtp:
smtp.starttls()
smtp.login(email_address, password)
smtp.send_message(msg)
print("\n✅ Mail sent successfully!")
except Exception as e:
print(f"\n❌ Failed to send email: {e}")
📤 Run Your Script
Now simply run the script using:
python mail.py
It will ask for the following inputs:
- SMTP Server:
smtp.gmail.com
- Port:
587
- Your Email
- Your Gmail App Password
- Recipient Email
- Subject
- Message Body
✅ If all goes well, your mail will be sent instantly!
🖼 Tool Interface Preview
📚 Related Articles
💬 My Final Thoughts
This simple mail-sending tool is a great way to learn about Python scripting, SMTP protocols, and Termux automation. It’s educational, beginner-friendly, and can be a stepping stone for bigger projects.
💡 Always use responsibly. Avoid using such scripts for spam or illegal activities.
If you want to upgrade this tool to send attachments, schedule emails, or build a GUI — let me know in the comments or reach out on Kumar’s Magic socials!