Replies: 2 comments
|
Fair questions. Two points to make here: When I was creating Mailrise, I envisioned the configuration format as a simple 1:1 mapping from email address to Apprise configuration YAML, since that seemed sufficient for the homelab purposes I had in mind. But clearly, it’s not sufficient to cover all of the use cases people are coming up with, especially organizational use. I think the current format has been overloaded enough and the goal should be to implement a new format flexible enough for everyone, perhaps something like what Junction did. You do already have the custom router API if you are handy with Python and need a fully customized solution. Mailrise already reads the email mimetype and forwards it to Apprise, so you should almost never have to use |
|
I know this discussion is super old but if folks want to do something like this, here's a basic router that acts as a simple SMTP relay with a few guardrails. It isn't super useful at the moment, but it can be extended to match different senders / recipients to build different / additional Apprise URLs to notify other services. from logging import Logger
from typing import Any, AsyncGenerator
from mailrise.router import AppriseNotification, EmailMessage, Router
from email import utils as email_utils
from urllib.parse import quote
class CustomRouter(Router):
MAILTO_BASE_URL = "mailto://localsmtpserver"
ALLOWED_SENDER_DOMAIN = "mycustomdomain.com"
DEFAULT_SENDER_NAME = "Admin"
DEFAULT_SENDER_EMAIL = "admin@mycustomdomain.com"
async def email_to_apprise(
self, logger: Logger, email: EmailMessage, auth_data: Any, **kwargs) \
-> AsyncGenerator[AppriseNotification, None]:
sender_name, sender_email = email_utils.parseaddr(email.from_)
if not sender_name:
logger.info("Sender name missing. Setting to '%s'.", self.DEFAULT_SENDER_NAME)
sender_name = self.DEFAULT_SENDER_NAME
if not sender_email:
logger.warning("Sender email missing. Setting to '%s'", self.DEFAULT_SENDER_EMAIL)
sender_email = self.DEFAULT_SENDER_EMAIL
elif not sender_email.lower().endswith(f"@{self.ALLOWED_SENDER_DOMAIN}"):
logger.warning(
"Sender email '%s' is not in the %s domain. Overriding to '%s'",
sender_email,
self.ALLOWED_SENDER_DOMAIN,
self.DEFAULT_SENDER_EMAIL
)
sender_email = self.DEFAULT_SENDER_EMAIL
for recipient in email.to:
_, recipient_email = email_utils.parseaddr(recipient)
apprise_url = (
f"{self.MAILTO_BASE_URL}"
f"?to={quote(recipient_email)}"
f"&from={quote(sender_email)}"
f"&name={quote(sender_name)}"
)
config_yaml = f'urls: ["{apprise_url}"]'
logger.info("Sending apprise notification: %s", apprise_url)
yield AppriseNotification(
config=config_yaml,
title=email.subject,
body=email.body,
body_format=email.body_format,
attachments=email.attachments,
config_format='yaml'
)
router = CustomRouter()
authenticator = None |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi!
I'm interested in having the mailrise app as a middleware for all applications and manage there all the accesses to other notification systems, but I'm encountering some issues. I have multiple questions about the app:
Additionally, you could add in the documentation for debugging purposes to use the following docker-compose command:
entrypoint: ["mailrise","-vv","/etc/mailrise.conf"]Thanks for your answers!
All reactions