https://github.com/helmi/python-smtp2http
A very basic SMTP to HTTP forwarder which enables webhooks to receive e-mails via SMTP.
https://github.com/helmi/python-smtp2http
Last synced: 10 months ago
JSON representation
A very basic SMTP to HTTP forwarder which enables webhooks to receive e-mails via SMTP.
- Host: GitHub
- URL: https://github.com/helmi/python-smtp2http
- Owner: Helmi
- Created: 2024-02-14T10:12:39.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-14T10:12:41.000Z (over 2 years ago)
- Last Synced: 2025-09-01T20:55:35.683Z (10 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# SMTP to HTTP Email Forwarder
This project contains a Python application that acts as a local SMTP server to receive emails and forward them to HTTP endpoints based on the recipient's email address. The intended use is for tools like n8n or other Webhook receivers to be able to receive email via SMTP.
### Content decoding
Currently the script only supports decoding of `text/plain` and `text/html` content types. It will ignore other content types.
### Test script
The repo also includes a script for easy sending of test emails to the main script locally.
## Requirements
- Python 3.7 or higher
- `aiosmtpd` library
- `requests` library
- `email` library
## Installation
Clone the repository and install the required Python libraries.
```bash
git clone https://github.com/yourusername/yourrepository.git
cd yourrepository
pip install -r requirements.txt
```
## Usage
To run the SMTP server, use the following command:
```bash
python smtp2http.py
```
To send a test email to the server, you can use the `local_test.py` script:
```bash
python local_test.py
```
Modify the file itself to make it fit your testing needs.
## Configuration
The script uses a configuration file (`email_config.json`) to map email addresses to HTTP endpoints. The configuration file should be in the following format:
```json
{
"email_endpoints": {
"known@example.com": "https://example.com/webhook"
},
"allowed_senders": [
"allowed-sender@example.com",
"another-sender@example.com"
]
}
```
## Logging
The script logs known and unknown emails separately. The logs are written to `known_emails.log` and `unknown_emails.log` respectively.
Logging may as well seen as WIP. I'm not happy with it yet but wanted to have basic logging going early.
## Security
The script includes basic checks for email format and malicious content. It also uses HTTPS for communication with the HTTP endpoints. However, it is recommended to further secure the script by implementing SPF, DKIM, and DMARC, and by securing the configuration file and logs.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## License
[MIT](https://choosealicense.com/licenses/mit/)