コード例 #1
0
def send_mail(request, templates_name, recipient_list, context=None):
    """Proxy for sending emails."""
    fail_silently = FAIL_SILENTLY
    auth_user = AUTH_USER
    auth_password = AUTH_PASSWORD
    connection = CONNECTION

    context = context or {}
    context.update({
        'protocol': 'https' if request.is_secure() else 'http',
        'domain': get_current_site(request).domain,
    })
    text_template = get_template('emails/{}.txt'.format(templates_name))
    html_template = get_template('emails/{}.html'.format(templates_name))

    bcc = list(get_administrators_emails().values())
    connection = connection or get_connection(username=auth_user,
                                              password=auth_password,
                                              fail_silently=fail_silently)
    # required, if omitted then no emails from BCC are send
    headers = {'bcc': ','.join(bcc)}
    email = EmailMultiAlternatives(SUBJECTS[templates_name],
                                   text_template.render(context),
                                   FROM_ADDRESS,
                                   recipient_list,
                                   bcc,
                                   connection=connection,
                                   headers=headers)
    email.attach_alternative(html_template.render(context), 'text/html')

    return email.send()
コード例 #2
0
ファイル: email.py プロジェクト: BernadetaNegra/volontulo
def send_mail(request, templates_name, recipient_list, context=None):
    u"""Proxy for sending emails."""
    fail_silently = FAIL_SILENTLY
    auth_user = AUTH_USER
    auth_password = AUTH_PASSWORD
    connection = CONNECTION

    context = Context(context or {})
    context.update({
        'protocol': 'https' if request.is_secure() else 'http',
        'domain': get_current_site(request).domain,
    })
    text_template = get_template('emails/{}.txt'.format(templates_name))
    html_template = get_template('emails/{}.html'.format(templates_name))

    bcc = list(get_administrators_emails().values())
    connection = connection or get_connection(
        username=auth_user,
        password=auth_password,
        fail_silently=fail_silently
    )
    # required, if omitted then no emails from BCC are send
    headers = {'bcc': ','.join(bcc)}
    email = EmailMultiAlternatives(
        SUBJECTS[templates_name],
        text_template.render(context),
        FROM_ADDRESS,
        recipient_list,
        bcc,
        connection=connection,
        headers=headers
    )
    email.attach_alternative(html_template.render(context), 'text/html')

    return email.send()
コード例 #3
0
class AdministratorContactForm(ContactForm):
    U"""Contact form specified for anyone to mail to administrator."""
    APPLICANTS = (
        ('VOLUNTEER', u'wolontariusz'),
        ('ORGANIZATION', u'organizacja'),
    )
    ADMINISTRATORS = [(key, value)
                      for key, value in get_administrators_emails().items()]
    applicant = forms.Select(choices=APPLICANTS)
    administrator = forms.Select(choices=ADMINISTRATORS)
コード例 #4
0
    def __init__(self, *args, **kwargs):
        """Administrator contant form initialization.

        Administrator choice need to be here, as new Django release tries to
        import this form during migrations, even if user table is not
        available.
        """
        super(AdministratorContactForm, self).__init__(*args, **kwargs)
        self.administrator = forms.Select(
            choices=get_administrators_emails().items(), )