Exemplo n.º 1
0
def make_mail(subject,
              text_template,
              html_template,
              context_vars,
              from_email,
              to_email,
              headers=None,
              **extra_kwargs):
    """Return an instance of EmailMultiAlternative with both plaintext and
    html versions."""
    default_headers = {
        'Reply-To': settings.DEFAULT_REPLY_TO_EMAIL,
    }
    if headers is not None:
        default_headers.update(headers)
    headers = default_headers

    mail = EmailMultiAlternatives(subject,
                                  render_email(text_template, context_vars),
                                  from_email,
                                  [to_email],
                                  headers=headers,
                                  **extra_kwargs)

    if html_template:
        html = transform(render_email(html_template, context_vars),
                         'https://' + Site.objects.get_current().domain)
        mail.attach_alternative(html, 'text/html')

    return mail
Exemplo n.º 2
0
def send_mail(to=[],
              subject='',
              html_template='',
              txt_template='',
              context={},
              from_email=settings.DEFAULT_FROM_EMAIL):
    """Send mail to the all contacts
    """
    from django.core import mail
    from django.core.mail import EmailMultiAlternatives
    from django.template.loader import render_to_string
    _to = to

    context.update({
        'SITE_URL': settings.SITE_URL,
    })

    text = render_to_string(txt_template, context)
    html = render_to_string(html_template, context)

    result = None

    with mail.get_connection() as connection:
        mail = EmailMultiAlternatives(
            subject=subject,
            body=text,
            from_email=from_email,
            to=_to,
            connection=connection,
        )
        mail.attach_alternative(html, "text/html")
        result = mail.send(fail_silently=True)
    return result
Exemplo n.º 3
0
 def mail_owner(self, project, subject, message, fail_silently=False, connection=None,
                html_message=None):
     """Sends a message to the admins, as defined by the ADMINS setting."""
     if not settings.ADMINS:
         return
     mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
                                   message, settings.SERVER_EMAIL, [project.owner.email],
                                   connection=connection)
     if html_message:
         mail.attach_alternative(html_message, 'text/html')
     mail.send(fail_silently=fail_silently)
Exemplo n.º 4
0
def make_mail(subject, text_template, html_template, context_vars, from_email,
              to_email, **extra_kwargs):
    """Return an instance of EmailMultiAlternative with both plaintext and
    html versions."""
    mail = EmailMultiAlternatives(subject,
                                  render_email(text_template, context_vars),
                                  from_email, [to_email], **extra_kwargs)

    if html_template:
        html = transform(render_email(html_template, context_vars),
                         'https://' + Site.objects.get_current().domain)
        mail.attach_alternative(html, 'text/html')

    return mail
Exemplo n.º 5
0
def make_mail(subject,
              text_template,
              html_template,
              context_vars,
              from_email,
              to_email,
              **extra_kwargs):
    """Return an instance of EmailMultiAlternative with both plaintext and
    html versions."""
    mail = EmailMultiAlternatives(subject,
                                  render_email(text_template, context_vars),
                                  from_email,
                                  [to_email],
                                  **extra_kwargs)

    if html_template:
        html = transform(render_email(html_template, context_vars),
                         'https://' + Site.objects.get_current().domain)
        mail.attach_alternative(html, 'text/html')

    return mail