Source

django-celery-email / djcelery_email / tasks.py

Paul McLanahan fd27c44 
Paul McLanahan b30b931 

Paul McLanahan 14dbaeb 
Paul McLanahan fd27c44 




Paul McLanahan 14dbaeb 
Paul McLanahan 5830629 
Paul McLanahan 14dbaeb 


Paul McLanahan b30b931 

Paul McLanahan 14dbaeb 
Yehonatan Daniv 038e73f 
Paul McLanahan 14dbaeb 
Paul McLanahan 92b4371 

Paul McLanahan 14dbaeb 
Yehonatan Daniv b72a75a 
Paul McLanahan 14dbaeb 
Yehonatan Daniv b72a75a 
Paul McLanahan a916b0b 
Paul McLanahan 14dbaeb 

Paul McLanahan a916b0b 


Paul McLanahan fd27c44 
Paul McLanahan 14dbaeb 

Paul McLanahan 58f9586 
from django.conf import settings
from django.core.mail import get_connection

from celery.task import task


CONFIG = getattr(settings, 'CELERY_EMAIL_TASK_CONFIG', {})
BACKEND = getattr(settings, 'CELERY_EMAIL_BACKEND',
                  'django.core.mail.backends.smtp.EmailBackend')
TASK_CONFIG = {
    'name': 'djcelery_email_send',
    'ignore_result': True,
}
TASK_CONFIG.update(CONFIG)


@task(**TASK_CONFIG)
def send_email(message, **kwargs):
    logger = send_email.get_logger()
    conn = get_connection(backend=BACKEND,
                          **kwargs.pop('_backend_init_kwargs', {}))
    try:
        result = conn.send_messages([message])
        logger.debug("Successfully sent email message to %r.", message.to)
        return result
    except Exception, e:
        # catching all exceptions b/c it could be any number of things
        # depending on the backend
        logger.warning("Failed to send email message to %r, retrying.",
                    message.to)
        send_email.retry(exc=e)


# backwards compat
SendEmailTask = send_email