Info
Simple SMTP daemon which can save incoming emails to MongoDB and send it to WebSocket.
You should own domain name, MX record and nginx.
Install
$ pip3 install mail2mongo
Run
$ mail2mongo --help
usage: main.py [-h] [-m MONGO_URI] [-db DB_NAME] [-cn COL_NAME] [-ap API_PORT]
[-sp SMTP_PORT] -d DOMAINS [DOMAINS ...]
Save incoming emails to mongodb
optional arguments:
-h, --help show this help message and exit
-m MONGO_URI, --mongo MONGO_URI
Mongo URI (default: mongodb://localhost)
-db DB_NAME, --db-name DB_NAME
Mongo data base (default: mail2mongo)
-cn COL_NAME, --col-name COL_NAME
Mongo collection name (default: emails)
-ap API_PORT, --api-port API_PORT
API port (default: 8080)
-sp SMTP_PORT, --smtp-port SMTP_PORT
SMTPD port (default: 8025)
-d DOMAINS [DOMAINS ...], --domains DOMAINS [DOMAINS ...]
Allowed domains (default: [])
Argument -d/--domains required! It's a domain names list which you own.
From python package
$ mail2mongo -d example.com -m mongodb://192.168.0.100:27017
From Docker image
$ docker run -p 8080:8080 -p 8025:8025 inn0kenty/mail2mongo -d example.com -m mongodb://192.168.0.100:27017
nginx
File /etc/nginx/nginx.conf should contains:
mail {
server_name <Your MX record>;
auth_http <local ip:port>/nginx-auth;
proxy_pass_error_message off;
server {
listen 25;
protocol smtp;
proxy on;
smtp_auth none;
xclient off;
}
}
The MX record usually has the form mail.example.com where example.com your domain name. The mail.example.com must be resolved to your ip address.
Local ip:port - local ip address and port (api_port, default 8080).
WebSocket
You can use WebSocket on /ws url. Also you should provide email address.
Example
import asyncio
import aiohttp
async def main():
async with aiohttp.ClientSession() as session:
async with session.ws_connect('ws://127.0.0.1:8080/ws?email=foo@example.com') as ws:
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
print(msg.json())
else:
break
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
You can get messages of two types:
If something go wrong:
{'type': 'error', 'payload': {'msg': 'Error message'}}
If you receive new email:
{'type': 'new_mail', 'payload': {'from': 'root@google.com', 'to': 'foo@example.com', 'subject': 'Foo bar', 'text': 'Some message', 'timestamp': '1970-01-01T00:00:00.000000+00:00', '_id': '5ae0988c754ea76f22935378'}}
_id - ObjectId in MongoDB.
Similar payload saved to MongoDB.
If for some reason MongoDB is down, service will continue try to save payload to mongo. At each next step service will be double sleep time (default is 60 seconds).
Metadata
Release files for mail2mongo 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mail2mongo-0.3.3.tar.gz | 6.4 kB | Without provenance | Details for mail2mongo-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mail2mongo-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for mail2mongo-0.3.3-py3-none-any.whl |
Total release size: 18.9 kB
Release files / mail2mongo-0.3.3.tar.gz
| Download URL | mail2mongo-0.3.3.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07dddf24f86b3252f69cc2ede7ac9f9b211a86553107c1072951c7dec8ca7ca3
|
|
BLAKE2b-256 checksum How to use checksums |
0531fec1f303928bba4dc435d93d1dfd31eceaae62ff6312be010cffef9ffdec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / mail2mongo-0.3.3-py3-none-any.whl
| Download URL | mail2mongo-0.3.3-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbae1abc33e12eb394b8a1a70cf5d8a29f11c1c44f242f6ff81e380dc3498985
|
|
BLAKE2b-256 checksum How to use checksums |
7dd1763fa9ea9fedae92c3fd82e8773bb2174d30f85f2d9876323ba00577faeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for mail2mongo 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.