mailrise
repository·main·Indexed 23 days ago
https://github.com/yoryan/mailriseAn SMTP gateway that converts incoming emails into Apprise notifications. It acts as an email relay for legacy or email-only devices (such as IoT devices, surveillance systems, or Linux servers) to send notifications to over 60+ services supported by Apprise, including Discord, Matrix, and Pushover.
What's inside mailrise
- Mailrise is an SMTP gateway that converts incoming emails into Apprise notifications. It acts as an email relay for devices or software that only support SMTP (like Linux servers, IoT devices, or surveillance systems), allowing them to send notifications to over 60+ services supported by Apprise (e.g., Matrix, Nextcloud, Discord, Pushover).
How Mailrise routing and configuration works
mainMailrise uses the recipient address of an incoming email to determine which Apprise configuration to use.
Routing Logic
- Configuration Selection: The username component of the recipient email address corresponds to a configuration name defined in your
configsblock.- Example: If your config has a
pushoverblock, sending an email topushover@mailrise.xyzwill use that configuration.
- Example: If your config has a
- Notification Types: You can append a
.<type>to the username to specify one of the four Apprise notification types (e.g.,failure). This can change the icon color in supported services.- Example:
discord.failure@mailrise.xyzselects thediscordconfig and sets the type tofailure.
- Example:
- Attachments: Email attachments are passed through to Apprise if the target notification service supports them.
# Example minimal configuration configs: pushover: urls: - pover://[...]- Configuration Selection: The username component of the recipient email address corresponds to a configuration name defined in your
Use Template Strings for Notifications
mainYou can customize how email content is transformed into notifications using Python template strings. Use the
$prefix to insert variables intotitle_templateandbody_template.Available variables:
subject: The email subject.from: The sender's full address.body: The full contents of the email body.to: The full email address of the selected Apprise configuration.config: The name of the selected Apprise configuration (or thetoaddress if a custom domain is used).type: The Apprise notification class (info,success,warning, orfailure).
Set up a local development environment for mailrise
mainTo contribute to
mailrise, follow these steps to prepare your local machine:1. Create an isolated virtual environment
Use
virtualenvorcondato avoid conflicts with your system packages.Using virtualenv:
virtualenv <PATH TO VENV> source <PATH TO VENV>/bin/activateUsing Miniconda:
conda create -n mailrise python=3 six virtualenv pytest pytest-cov conda activate mailrise2. Clone and install the package
Fork the repository on your service (e.g., GitHub), then clone your fork and install the package in editable mode so changes are reflected in your Python REPL.
git clone git@github.com:YourLogin/mailrise.git cd mailrise pip install -U pip setuptools -e .3. Install pre-commit hooks
mailriseusespre-committo automatically check code style (usingflake8andblack) and other quality metrics.pip install pre-commit pre-commit installgit clone git@github.com:YourLogin/mailrise.git cd mailrise pip install -U pip setuptools -e . pip install pre-commit pre-commit installCompile and preview documentation locally
mainThe
mailrisedocumentation is built using Sphinx. To compile the documentation locally for testing changes, usetox:tox -e docsOnce compiled, you can preview the documentation in your browser using Python's built-in web server:
python3 -m http.server --directory 'docs/_build/html'Then navigate to
http://localhost:8000in your web browser.tox -e docs python3 -m http.server --directory 'docs/_build/html'Setup TLS with Traefik (Recommended)
mainInstead of managing certificates inside Mailrise, you can run Mailrise in plaintext and use Traefik to handle TLS/ACME (Let's Encrypt). This allows SMTP clients to connect via
TLS-on-connect(Port 465).Example
docker-compose.ymlsnippet:mailrise: image: yoryan/mailrise container_name: mailrise restart: unless-stopped volumes: - ./mailrise.conf:/etc/mailrise.conf:ro labels: traefik.tcp.routers.mailrise.rule: "HostSNI(`*`)" traefik.tcp.routers.mailrise.tls: "true" traefik.tcp.routers.mailrise.tls.certresolver: "letsencrypt" traefik.tcp.routers.mailrise.tls.domains[0].main: "my.public.mailrise.domain.com" traefik.tcp.routers.mailrise.tls.domains[0].sans: "" traefik.tcp.routers.mailrise.entrypoints: "mailsecure"And
traefik.ymlconfiguration:entryPoints: mailsecure: address: ":465"mailrise: image: yoryan/mailrise container_name: mailrise restart: unless-stopped volumes: - ./mailrise.conf:/etc/mailrise.conf:ro labels: traefik.tcp.routers.mailrise.rule: "HostSNI(`*`)" traefik.tcp.routers.mailrise.tls: "true" traefik.tcp.routers.mailrise.tls.certresolver: "letsencrypt" traefik.tcp.routers.mailrise.tls.domains[0].main: "my.public.mailrise.domain.com" traefik.tcp.routers.mailrise.tls.domains[0].sans: "" traefik.tcp.routers.mailrise.entrypoints: "mailsecure"Install Mailrise via Docker
mainYou can use the official Docker image from Docker Hub. You must bind mount a configuration file to
/etc/mailrise.conf.Important: The mount must be a file, not a directory.
NAS Specific Instructions
- Unraid: Since Unraid only supports directory passthrough, do not attempt to bind mount the file directly as it may break your system. Instead, override the image's default command to use a volume flag like
-v /etc/myconfig/mailrise.confso you can pass through a directory containing the config. - TrueNAS SCALE: Mailrise is designed to run as a non-root container. Ensure the container is running as user
999and group999to avoid permission issues.
- Unraid: Since Unraid only supports directory passthrough, do not attempt to bind mount the file directly as it may break your system. Instead, override the image's default command to use a volume flag like
Install Mailrise from PyPI
mainMailrise is available on PyPI. The minimum required Python version is 3.8+.
After installation, you should create a configuration file and run Mailrise as a service. Below is a suggested
systemdunit file for running Mailrise as a service:[Unit] Description=Mailrise SMTP notification relay [Service] ExecStart=/usr/local/bin/mailrise /etc/mailrise.conf [Install] WantedBy=multi-user.targetWorkflow for submitting code contributions
mainFollow this workflow to ensure your code changes are accepted:
- Discuss first: For non-trivial changes, open an issue in the
issue trackerto discuss your approach before writing code. - Branching: Never work on the
mainbranch. Create a feature branch:git checkout -b my-feature - Implementation:
- Add docstrings to new functions, modules, and classes (especially public APIs).
- Add yourself to
AUTHORS.rst. - Crucial: Add unit tests and documentation for any new features.
- Validation:
- Ensure
pre-commitpasses all checks. - Run tests using
toxto ensure no regressions:tox
(Use `tox -av` to see available checks). - Ensure
- Commit and Push:
git add <MODIFIED FILES> git commit git push -u origin my-feature - Submit: Go to your fork's web page and click the button to create a Pull Request.
git checkout -b my-feature git add <MODIFIED FILES> git commit git push -u origin my-feature- Discuss first: For non-trivial changes, open an issue in the
Install Mailrise from source
mainTo install Mailrise in editable mode for development or debugging, usepipwith the testing extras. To build a wheel, usetox.Determine notification type from email address
mainThe
SimpleRoutercan automatically determine the AppriseNotifyType(severity) based on the suffix of the recipient's username. If a suffix is detected, the router uses that type; otherwise, it defaults toINFO.Supported suffixes are:
.info$\rightarrow$apprise.NotifyType.INFO(Default).success$\rightarrow$apprise.NotifyType.SUCCESS.warning$\rightarrow$apprise.NotifyType.WARNING.failure$\rightarrow$apprise.NotifyType.FAILURE
Example: Sending an email to
alerts.failure@mailrise.xyzwill trigger a notification with theFAILUREseverity level.Extend Mailrise with custom Python code
mainMailrise allows you to plug in custom logic for routing and authentication by importing external Python modules. You can specify a path to a Python file using the
import_codekey in your configuration.The imported module should provide (optionally):
router: A customRouterinstance.authenticator: A customAuthenticatorTypeinstance.
If
import_codeis provided, Mailrise will attempt to load the module and use its provided components. If they are not present, it falls back to the default simple router and authenticator.