SSL/TLS SendMail with Attachment
Overview
This application demonstrates how to send emails with plain text attachments using a secure SSL/TLS connection. The application provides a web-based interface for composing and sending emails through an SMTP server with authentication.
Features
- Secure SSL/TLS email transmission
- Web-based user interface
- SMTP authentication support
- Plain text email attachments
- Real-time feedback and error reporting
- DNS resolution for SMTP servers
Requirements
- Network connection with DHCP support
- SSL/TLS capable SMTP server
- Compatible web browser for interface access
Application Components
main.cpp
The main application entry point that:
- Initializes the network stack
- Enables system diagnostics
- Starts the HTTPS web server on default port 443
- Waits for network connectivity via DHCP
- Runs the main application loop
webfuncs.cpp
Contains the web interface functionality including:
- Form data handling for email parameters
- POST request processing
- Email composition and transmission
- Error handling and status reporting
- MIME attachment support
Web Interface
The application provides form fields for:
- Username: SMTP authentication username
- Password: SMTP authentication password
- Server: SMTP server hostname or IP address
- Port: SMTP server port (default: 465 for SSL/TLS)
- From: Sender email address
- To: Recipient email address
- Subject: Email subject line
- Body: Email message content
- Attachment: Plain text attachment content
Configuration
SMTP Server Settings
- Default port: 465 (SSL/TLS)
- Authentication: Required
- Connection type: SSL/TLS (not STARTTLS)
Google Account Setup
When using Gmail or Google Workspace accounts:
- Enable "Less secure app access" in account settings
- For 2FA-enabled accounts, create an application password at:
https://myaccount.google.com/apppasswords
Usage
- Network Setup: Ensure the device has network connectivity and can obtain a DHCP address
- Access Interface: Navigate to the device's HTTPS web interface
- Configure Email: Fill in all required form fields
- Send Email: Submit the form to transmit the email
- View Results: Check the results page for success/failure status
Technical Details
Memory Allocation
- Username: 80 characters
- Password: 80 characters
- Server: 80 characters
- Server Port: 6 characters
- From/To addresses: 80 characters each
- Subject: 256 characters
- Body: 16,000 characters
- Attachment: 16,000 characters
Error Handling
The application provides detailed error reporting including:
- DNS resolution status
- SMTP server connection results
- Authentication success/failure
- Detailed server response logs
Security Considerations
- Uses SSL/TLS encryption for all SMTP communications
- Passwords are handled securely in memory
- Web interface operates over HTTPS
Limitations
- Supports plain text attachments only
- Single attachment per email
- Does not support STARTTLS (use dedicated SSL/TLS connection)
- No file system integration (attachment content entered via web form)
Troubleshooting
Common Issues
- DNS Resolution Failed: Verify SMTP server hostname is correct
- Authentication Failed: Check username/password and account settings
- Connection Timeout: Verify server address and port number
- SSL/TLS Errors: Ensure server supports SSL/TLS on specified port
Debug Information
Enable system diagnostics in the code to view detailed connection and transmission logs through the serial console.
Related Examples
For applications requiring file system integration, refer to the EFFS (Embedded Flash File System) SendMail examples that support file-based attachments.