예제 #1
0
def send_email(recipient,
               subject,
               message,
               from_email=None,
               html_message=None,
               attachments=None,
               real_email=False,
               cc=None,
               headers=None,
               max_retries=3,
               reply_to=None,
               **kwargs):
    backend = EmailMultiAlternatives if html_message else EmailMessage
    connection = get_email_backend(real_email)

    result = backend(subject,
                     message,
                     from_email,
                     to=recipient,
                     cc=cc,
                     connection=connection,
                     headers=headers,
                     attachments=attachments,
                     reply_to=reply_to)

    if html_message:
        result.attach_alternative(html_message, 'text/html')
    try:
        result.send()
        return True
    except Exception as e:
        log.exception('send_mail() failed with error: %s, retrying' % e)
        return send_email.retry(exc=e, max_retries=max_retries)
예제 #2
0
파일: tasks.py 프로젝트: eviljeff/olympia
def send_email(recipient, subject, message, from_email=None,
               html_message=None, attachments=None, real_email=False,
               cc=None, headers=None, max_retries=3, reply_to=None,
               **kwargs):
    backend = EmailMultiAlternatives if html_message else EmailMessage
    connection = get_email_backend(real_email)

    result = backend(subject, message, from_email, to=recipient, cc=cc,
                     connection=connection, headers=headers,
                     attachments=attachments, reply_to=reply_to)

    if html_message:
        result.attach_alternative(html_message, 'text/html')
    try:
        result.send()
        return True
    except Exception as e:
        log.exception('send_mail() failed with error: %s, retrying' % e)
        return send_email.retry(exc=e, max_retries=max_retries)
예제 #3
0
def send_email(recipient,
               subject,
               message,
               from_email=None,
               html_message=None,
               attachments=None,
               real_email=False,
               cc=None,
               headers=None,
               fail_silently=False,
               async=False,
               max_retries=None,
               reply_to=None,
               **kwargs):
    backend = EmailMultiAlternatives if html_message else EmailMessage
    connection = get_email_backend(real_email)

    result = backend(subject,
                     message,
                     from_email,
                     to=recipient,
                     cc=cc,
                     connection=connection,
                     headers=headers,
                     attachments=attachments,
                     reply_to=reply_to)

    if html_message:
        result.attach_alternative(html_message, 'text/html')
    try:
        result.send(fail_silently=False)
예제 #4
0
from olympia.amo.utils import get_email_backend
from olympia.bandwagon.models import Collection
from olympia.devhub.models import ActivityLog
from olympia.stats.models import Contribution


log = commonware.log.getLogger('z.task')


@task
def send_email(recipient, subject, message, from_email=None,
               html_message=None, attachments=None, real_email=False,
               cc=None, headers=None, fail_silently=False, async=False,
               max_retries=None, reply_to=None, **kwargs):
    backend = EmailMultiAlternatives if html_message else EmailMessage
    connection = get_email_backend(real_email)

    result = backend(subject, message, from_email, to=recipient, cc=cc,
                     connection=connection, headers=headers,
                     attachments=attachments, reply_to=reply_to)

    if html_message:
        result.attach_alternative(html_message, 'text/html')
    try:
        result.send(fail_silently=False)
        return True
    except Exception as e:
        log.error('send_mail failed with error: %s' % e)
        if async:
            return send_email.retry(exc=e, max_retries=max_retries)
        elif not fail_silently: