gwcelery.email module

Embed an IMAP email client into a Celery worker by extending Celery with bootsteps.

gwcelery.email.install(app)[source]

Register the email client subsystem in the application boot steps.

gwcelery.email.bootsteps module

class gwcelery.email.bootsteps.Receiver(consumer, email=False, **kwargs)[source]

Bases: EmailBootStep

Run the global email receiver in background thread.

name = 'email client'
start(consumer)[source]
stop(consumer)[source]

gwcelery.email.signals module

Definitions of custom Celery signals related to emails.

These signals allow us to keep the VOEvent validation code decoupled from the email client itself.

gwcelery.email.signals.email_received = <Signal: email_received providing_args={'rfc822'}>

Fired whenever an email message is received.

Parameters:

rfc822 (bytes) – The RFC 822 contents of the message.

Examples

Register an email listener like this:

import email
import email.policy

@email_received.connect
def on_email_received(rfc822, **kwargs):
    # Parse the RFC822 email.
    message = email.message_from_bytes(rfc822, policy=email.policy.default)
    # Print some of the message headers.
    print('Subject:', message['Subject'])
    print('From:', message['From'])
    # Print the plain-text message body.
    body = message.get_body(['plain']).get_content()
    print(body)