ox.apps.mails

This application provide mail sending capabilities to Oxylus. Mails are sent in background tasks.

It allows users to configure multiple email accounts and send simple mail. The programmation interface allows extensible and custom mail sending.

Models

class ox.apps.mails.models.BaseMail(*args, **kwargs)[source]

Base class for outgoing emails. Later is it planned for incoming too.

This is an abstract model as it shall be subclassed.

Access

alias of BaseMailAccess

class State(*values)[source]
get_content()[source]

Return raw content.

get_context(**context)[source]

Return mail context.

Return type:

Context

get_recipients()[source]

Return the recipients of the mail.

Return type:

list[tuple[str, Context]]

get_subject()[source]

Return raw subject.

parent_attr = 'account'

Field name used for parenting.

class ox.apps.mails.models.Mail(*args, **kwargs)[source]

A simple mail sending to a list of recipients as string.

Access

alias of MailAccess

exception DoesNotExist
exception MultipleObjectsReturned
class State(*values)
get_recipients()[source]

Return recipients with context filled with name and email.

recipients

Recipients, as a list of email strings.

class ox.apps.mails.models.MailAccount(*args, **kwargs)[source]

Configure an email account used to send mails.

Access

alias of MailAccountAccess

exception DoesNotExist
class Encryption(*values)[source]
exception MultipleObjectsReturned

ox.apps.mails.apps

class ox.apps.mails.apps.AppConfig(*args, **kwargs)[source]
icon: str = 'mdi-mail'

Material design icon class.

npm_package: str | None = '@oxylus/mails'

Name of the corresponding NPM package to look up for.

Defaults to app label.

root_url: str = 'ox/mails'

Provide an alternative to app label when we target application in paths.

For example Oxylus will nest template directories as ox/core/ instead of ox_core. The same happens for urls.

ox.apps.mails.send

class ox.apps.mails.send.MailSend(mail, renderer, account=None)[source]

This class handles sending an email from a model subclassing BaseMail.

account: MailAccount

Email account used to send the message. Defaults to mail’s one.

add_attachment(message, file)[source]

Add attachments to mail.

add_attachments(message, files)[source]

Add attachments to mail.

get_content(context)[source]

Render content to HTML and return.

Return type:

str

get_message(recipient, context)[source]

Return EmailMessage to send to provided recipient with rendered content and subject.

Parameters:
  • contact – target contact

  • context (Context) – extra context

Return type:

EmailMessage

mail: BaseMail

Outgoing mail

renderer: Renderer

Renderer used for user content.

Important

The variables must match context provided by this class and the method models.BaseMail.get_recipients() of mail instance.

send(context={})[source]

Send the mail to all mail’s recipients (models.BaseMail.get_recipients()) through SMTP.

Update the mail state once sent.

Parameters:

context (dict[str, Any]) – extra context to pass down to content’s Template

send_mail(smtp, recipient, context)[source]

Send mail to provided recipient.

Parameters:
  • smtp (SMTP) – logged in smtp instance.

  • recipient (str) – target email.

  • context (dict[str, Any]) – extra context data.

property templates: dict[str, Template][source]

Dict of templates instance for each renderable part of the message.

The keys will be: subject, header, content, signature, footer.

ox.apps.mails.serializers

class ox.apps.mails.serializers.MailAccountSerializer(*args, **kwargs)[source]
class ox.apps.mails.serializers.MailSerializer(*args, **kwargs)[source]

ox.apps.mails.tasks

ox.apps.mails.views

class ox.apps.mails.views.BaseMailViewSet(**kwargs)[source]

Base viewset to use for editing and sending emails.

You must specify permissions for the action ``send``! For example:

perms_map = {
    # Adapt for your own model
    "send": ["ox_mails.change_mail"],
}
renderer_path = 'ox.apps.mails.renderers.renderer'

Specify which renderer the MailSend class should use.

send(request, uuid=None)[source]

Trigger django task to send a mail and return an updated mail instance.

Task is send.send_mail().

class ox.apps.mails.views.MailAccountViewSet(**kwargs)[source]
serializer_class

alias of MailAccountSerializer

class ox.apps.mails.views.MailViewSet(**kwargs)[source]

View set for the models.Mail.

serializer_class

alias of MailSerializer