Files
InvenTree/src/backend/InvenTree/plugin/base/mail/mixins.py
Matthias Mair 45daef8442 feat: more mail sending backends and plugability (#9608)
* [FR] Improve Email handeling
Fixes #7950

* extend implementation of email thread and message models

* add missing args

* add unit test

* increase test coverage

* make key not necessary

* do not consider in coverage

* add email apis

* Add email admin

* fix email configuration check

* improve rendering

* squash migrations

* add config value overview

* log if mails were send

* add additional headers

* fix api unit test

* fix url resolving

* add InvenTree specific task to issue mails
required to extend sending options (prio, reply to)

* use internal sending task to keep telemetry cleaner

* add prio handling

* add plugin handling

* add setting

* factor plugin method out

* add typing

* move function

* bump version

* fix import path

* add a test for the test endpoint

* fix checking logic

* Add anymail sending / tracking handling

* add more ordering fields to api

* remove unneeded assingment

* add basic docs

* handle incoming emails with anymail

* Add inbox handling
Closes https://github.com/inventree/InvenTree/issues/7951

* add list of supported ESPs

* add better error transparency when sending fails

* add missing migration

* combine migrations back down

* fix todos

* fix qc export

* fix missing model props

* add tests

* ensure things are passed as a list

* fix list formatting

* fix deps

* move tests

* add testing with anymail

* allow handling of priority and headers

* add test for events

* add test for inbound messages

* rename variable

* increase coverage

* fix format

* add setting doc

* fix link

* rename fnc

* disable pro test

* make messages clearer

* fix doc syntax

* fix assign

* fix test

* revert test disablement

* add enum

* disable check for now

* try changing test around

* add incoming mail processing

* fix import

* add docs

* Fix mail.md

* bump deps

* fix api version
2025-06-20 11:49:02 +10:00

40 lines
1.2 KiB
Python

"""Plugin mixin class for mails."""
from django.core.mail import EmailMessage
from plugin import PluginMixinEnum
from plugin.helpers import MixinNotImplementedError
class MailMixin:
"""Mixin that provides support for processing mails before/after going to the sending/receiving commands.
Implementing classes must provide a "process_mail_out" and "process_mail_in" function:
"""
def process_mail_out(self, mail: EmailMessage, *args, **kwargs) -> None:
"""Function to handle a mail that is going to be send.
Must be overridden by plugin.
"""
# Default implementation does not do anything
raise MixinNotImplementedError
def process_mail_in(self, mail: EmailMessage, *args, **kwargs) -> None:
"""Function to handle a mail that was received.
Must be overridden by plugin.
"""
# Default implementation does not do anything
raise MixinNotImplementedError
class MixinMeta:
"""Meta options for this mixin."""
MIXIN_NAME = 'Mail'
def __init__(self):
"""Register the mixin."""
super().__init__()
self.add_mixin(PluginMixinEnum.MAIL, True, __class__)