A lightweight Python implementation of an SMTP client that sends emails using raw socket programming with TLS/SSL encryption.
This project demonstrates a low-level understanding of email protocols by implementing an SMTP client from scratch using Python's socket library. The client establishes a secure connection with an SMTP server, authenticates using the AUTH LOGIN method, and sends emails following the SMTP protocol specifications.
- Raw Socket Implementation: Direct TCP connection to SMTP servers without high-level libraries
- TLS/SSL Encryption: Implements STARTTLS for secure communication
- SMTP Authentication: Base64-encoded authentication using AUTH LOGIN
- RFC Compliant: Follows SMTP protocol standards (RFC 5321, RFC 3207)
- Full SMTP Transaction: Demonstrates complete email sending workflow
The client implements the following SMTP commands in sequence:
- EHLO - Extended hello to identify client to server
- STARTTLS - Upgrade connection to TLS encryption
- AUTH LOGIN - Authenticate with Base64-encoded credentials
- MAIL FROM - Specify sender email address
- RCPT TO - Specify recipient email address
- DATA - Send email headers and message body
- QUIT - Close the connection
- Python 3.x
- Standard library modules:
socket,ssl,base64
Update the following variables in the script:
email = "your-email@example.com"
email_bytes = b"your-email@example.com"
password = b"your-app-password"
target_email = "recipient@example.com"
mailserver = ("smtp.server.com", 587)Note: Use app-specific passwords for services like Yahoo, Gmail, etc., not your regular account password.
Run the script:
python smtp_client.pyThe client will output the server responses at each step of the SMTP transaction.
This project demonstrates:
- Understanding of network protocols and socket programming
- Knowledge of secure communication using TLS/SSL
- Implementation of authentication mechanisms
- Practical application of RFC specifications
- Email infrastructure and SMTP workflow
- RFC 3207 - SMTP Service Extension for Secure SMTP over TLS
- RFC 5321 - Simple Mail Transfer Protocol
- Python SSL Module Documentation
This is an educational project. In production environments, use established libraries like smtplib and never hardcode credentials in source code. Always use environment variables or secure credential management systems.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
This project is available for educational purposes.