当前位置: 首页>>代码示例>>Python>>正文


Python mail.EmailMultiAlternatives方法代码示例

本文整理汇总了Python中django.core.mail.EmailMultiAlternatives方法的典型用法代码示例。如果您正苦于以下问题:Python mail.EmailMultiAlternatives方法的具体用法?Python mail.EmailMultiAlternatives怎么用?Python mail.EmailMultiAlternatives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.mail的用法示例。


在下文中一共展示了mail.EmailMultiAlternatives方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_email_ticket_confirm

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_email_ticket_confirm(request, payment_info):
    """
    :param request Django request object
    :param payment_info Registration object
    """
    mail_title = u"PyCon Korea 2015 등록확인 안내(Registration confirmation)"
    product = Product()
    variables = Context({
        'request': request,
        'payment_info': payment_info,
        'amount': product.price
    })
    html = get_template('mail/ticket_registered_html.html').render(variables)
    text = get_template('mail/ticket_registered_text.html').render(variables)
    
    msg = EmailMultiAlternatives(
        mail_title,
        text,
        settings.EMAIL_SENDER,
        [payment_info.email])
    msg.attach_alternative(html, "text/html")
    msg.send(fail_silently=False) 
开发者ID:pythonkr,项目名称:pyconkr-2015,代码行数:24,代码来源:helper.py

示例2: create_digest_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def create_digest_email(user, digest_frequency, as_of):
    """Return the digest email message for user based on when they last received a digest message."""
    start = user_digest_start(user, digest_frequency, as_of)
    context = notification_digest(user, start, as_of)

    logger.debug('Digest as of %s: %s', start, context)

    if context:
        context['timestamp'] = as_of
        context['site'] = Site.objects.get_current()
        context['digest_frequency'] = digest_frequency.name

        subject = render_to_string('boards/email/email_digest_subject.txt', context=context)
        # remove superfluous line breaks
        subject = " ".join(subject.splitlines()).strip()

        text_body = render_to_string('boards/email/email_digest_message.txt', context=context)
        html_body = render_to_string('boards/email/email_digest_message.html', context=context)

        email = EmailMultiAlternatives(subject=subject, body=text_body, to=[user.email])
        email.attach_alternative(html_body, "text/html")
        return email
    else:
        return None 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:26,代码来源:digest.py

示例3: email_user

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def email_user(self, text_template, html_template, context):
        offering = context['offering']
        headers = {
                'Precedence': 'bulk',
                'Auto-Submitted': 'auto-generated',
                'X-coursys-topic': 'discussion',
                'X-course': offering.slug,
                'Sender': settings.DEFAULT_SENDER_EMAIL,
                }
        to_email = context['to'].email()
        if offering.taemail():
            from_email = "%s <%s>" % (offering.name(), offering.taemail())
        else:
            from_email = settings.DEFAULT_SENDER_EMAIL
        text_content = get_template(text_template).render(context)
        html_content = get_template(html_template).render(context)
        
        msg = EmailMultiAlternatives(context['subject'], text_content, from_email, [to_email], headers=headers)
        msg.attach_alternative(html_content, "text/html")
        msg.send() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:models.py

示例4: email_notify_new_owner

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def email_notify_new_owner(self, request, admin):
        plaintext = get_template('onlineforms/emails/notify_new_owner.txt')
        html = get_template('onlineforms/emails/notify_new_owner.html')

        full_url = request.build_absolute_uri(reverse('onlineforms:view_submission',
                                    kwargs={'form_slug': self.form.slug,
                                            'formsubmit_slug': self.slug}))
        email_context = {'formsub': self, 'admin': admin, 'adminurl': full_url}
        subject = '%s submission transferred' % (self.form.title)
        from_email = FormFiller.form_full_email(admin)
        to = self.owner.notify_emails()
        msg = EmailMultiAlternatives(subject=subject, body=plaintext.render(email_context),
                from_email=from_email, to=to, bcc=[admin.full_email()],
                headers={'X-coursys-topic': 'onlineforms'})
        msg.attach_alternative(html.render(email_context), "text/html")
        msg.send()

        FormLogEntry.create(form_submission=self, category='MAIL',
                    description='Notified group "%s" that form submission was transferred to them.'
                                % (self.owner.name,)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:models.py

示例5: email_memo

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def email_memo(self):
        """
        Emails the registration confirmation email if there is one and if none has been emailed for this registration
        before.
        """
        # If this registration is waitlisted, don't email!
        if self.waitlisted:
            return
        if 'email' not in self.config and self.event.registration_email_text:
            subject = 'Registration Confirmation'
            from_email = settings.DEFAULT_FROM_EMAIL
            content = self.event.registration_email_text
            msg = EmailMultiAlternatives(subject, content, from_email,
                                         [self.email], headers={'X-coursys-topic': 'outreach'})
            msg.send()
            self.email_sent = content
            self.save() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:models.py

示例6: email_contract

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def email_contract(self):
        unit = self.posting.unit
        try:
            contract_email = unit.contract_email_text
            content = contract_email.content
            subject = contract_email.subject
        except TAContractEmailText.DoesNotExist:
            content = DEFAULT_EMAIL_TEXT
            subject = DEFAULT_EMAIL_SUBJECT

        response = HttpResponse(content_type="application/pdf")
        response['Content-Disposition'] = 'inline; filename="%s-%s.pdf"' % (self.posting.slug,
                                                                            self.application.person.userid)
        ta_form(self, response)
        to_email = self.application.person.email()
        if self.posting.contact():
            from_email = self.posting.contact().email()
        else:
            from_email = settings.DEFAULT_FROM_EMAIL
        msg = EmailMultiAlternatives(subject, content, from_email,
                                     [to_email], headers={'X-coursys-topic': 'ta'})
        msg.attach(('"%s-%s.pdf' % (self.posting.slug, self.application.person.userid)), response.getvalue(),
                   'application/pdf')
        msg.send() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:models.py

示例7: notify_mobile_survey_start

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def notify_mobile_survey_start(self, request, mobile_survey):
        admin_email = settings.ADMINS[0][1] if settings.ADMINS else ""
        email_context = {
            "button_text": _("Logon to {app_name}".format(app_name=settings.APP_NAME)),
            "link": request.build_absolute_uri(reverse("home")),
            "greeting": _(
                "Welcome to Arches!  You've just been added to a Mobile Survey.  \
                Please take a moment to review the mobile_survey description and mobile_survey start and end dates."
            ),
            "closing": _(f"If you have any qustions contact the site administrator at {admin_email}."),
        }

        html_content = render_to_string("email/general_notification.htm", email_context)
        text_content = strip_tags(html_content)  # this strips the html, so people will have the text as well.

        # create the email, and attach the HTML version as well.
        for user in self.get_mobile_survey_users(mobile_survey):
            msg = EmailMultiAlternatives(
                _("You've been invited to an {app_name} Survey!".format(app_name=settings.APP_NAME)),
                text_content,
                admin_email,
                [user.email],
            )
            msg.attach_alternative(html_content, "text/html")
            msg.send() 
开发者ID:archesproject,项目名称:arches,代码行数:27,代码来源:mobile_survey.py

示例8: send_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_mail(self, subject_template_name, email_template_name,
                  context, from_email, to_email, html_email_template_name=None):
        """
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        """
        subject = loader.render_to_string(subject_template_name, context)
        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())
        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name, context)
            email_message.attach_alternative(html_email, 'text/html')

        email_message.send() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:forms.py

示例9: send_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_mail(self, subject_template_name, email_template_name,
                  context, from_email, to_email, html_email_template_name=None):
        """
        Send a django.core.mail.EmailMultiAlternatives to `to_email`.
        """
        subject = loader.render_to_string(subject_template_name, context)
        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())
        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name, context)
            email_message.attach_alternative(html_email, 'text/html')

        email_message.send() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:18,代码来源:forms.py

示例10: send_complex_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_complex_mail(subject,
                      template_txt,
                      template_html,
                      _from,
                      to=None,
                      cc=None,
                      bcc=None,
                      context=None):

    context = {} if not context else context
    subject, from_email = subject, _from
    context['BASE_URL'] = settings.BASE_DOMAIN
    text_content = render_to_string(template_txt, Context(context))
    html_content = render_to_string(template_html, Context(context))

    msg = EmailMultiAlternatives(subject,
                                 text_content,
                                 from_email,
                                 to=to,
                                 cc=cc,
                                 bcc=bcc)
    msg.attach_alternative(html_content, "text/html")
    msg.send(fail_silently=True) 
开发者ID:arguman,项目名称:arguman.org,代码行数:25,代码来源:utils.py

示例11: send_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_email(to, kind, cc=[], **kwargs):

    current_site = Site.objects.get_current()

    ctx = {"current_site": current_site, "STATIC_URL": settings.STATIC_URL}
    ctx.update(kwargs.get("context", {}))
    subject = "[%s] %s" % (
        current_site.name,
        render_to_string(
            "symposion/emails/%s/subject.txt" % kind, ctx
        ).strip(),
    )

    message_html = render_to_string(
        "symposion/emails/%s/message.html" % kind, ctx
    )
    message_plaintext = strip_tags(message_html)

    from_email = settings.DEFAULT_FROM_EMAIL

    email = EmailMultiAlternatives(
        subject, message_plaintext, from_email, to, cc=cc
    )
    email.attach_alternative(message_html, "text/html")
    email.send() 
开发者ID:pydata,项目名称:conf_site,代码行数:27,代码来源:mail.py

示例12: send_mass_html_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_mass_html_mail(datatuple, fail_silently=False, user=None, password=None,
                        connection=None):
    """
    Given a datatuple of (subject, text_content, html_content, from_email,
    recipient_list), sends each message to each recipient list. Returns the
    number of emails sent.

    If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
    If auth_user and auth_password are set, they're used to log in.
    If auth_user is None, the EMAIL_HOST_USER setting is used.
    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
    """
    connection = connection or get_connection(
        username=user, password=password, fail_silently=fail_silently)
    messages = []
    default_from = settings.DEFAULT_FROM_EMAIL
    for subject, text, html, from_email, recipients in datatuple:
        message = EmailMultiAlternatives(
            subject, text, default_from, recipients,
            headers={'Reply-To': 'Pasporta Servo <saluton@pasportaservo.org>'})
        message.attach_alternative(html, 'text/html')
        messages.append(message)
    return connection.send_messages(messages) or 0 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:25,代码来源:utils.py

示例13: send_temporary_password

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_temporary_password(self):
        password = User.objects.make_random_password()
        self.set_password(password)
        subject, from_email, to = (
            "OpenCloud Account Credentials",
            "support@opencloud.us",
            str(self.email),
        )
        text_content = "This is an important message."
        userUrl = "http://%s/" % get_request().get_host()
        html_content = (
            """<p>Your account has been created on OpenCloud. Please log in <a href="""
            + userUrl
            + """>here</a> to activate your account<br><br>Username: """
            + self.email
            + """<br>Temporary Password: """
            + password
            + """<br>Please change your password once you successully login into the site.</p>"""
        )
        msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
        msg.attach_alternative(html_content, "text/html")
        msg.send() 
开发者ID:open-cloud,项目名称:xos,代码行数:24,代码来源:user.py

示例14: send_template

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_template(email, subject, template_name, context=None, logger=logger):
    """Construct and send an email with subject `subject` to `email`, using the
    named email template.
    """
    context = context or {}
    html, text = render_email_body(template_name, context)

    mail = EmailMultiAlternatives(
        from_email=f"{settings.EMAIL_NAME} <{settings.EMAIL_ADDRESS}>",
        subject=subject,
        body=text,
        to=(email if isinstance(email, list) else [email]))
    mail.attach_alternative(html, "text/html")
    mail.send()
    logger.info("Sent '%s' email to %s", template_name,
                email) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:18,代码来源:mail.py

示例15: send_request_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 别名]
def send_request_email(self, form):
        subject = '[HKN] Confirm Officer Challenge'
        officer_email = form.instance.officer.email

        confirm_link = self.request.build_absolute_uri(
                reverse("candidate:challengeconfirm", kwargs={ 'pk' : form.instance.id }))
        html_content = render_to_string(
            'candidate/challenge_request_email.html',
            {
                'subject': subject,
                'candidate_name' : form.instance.requester.get_full_name(),
                'candidate_username' : form.instance.requester.username,
                'confirm_link' : confirm_link,
                'img_link' : get_rand_photo(),
            }
        )
        msg = EmailMultiAlternatives(subject, subject,
                'no-reply@hkn.eecs.berkeley.edu', [officer_email])
        msg.attach_alternative(html_content, "text/html")
        msg.send() 
开发者ID:compserv,项目名称:hknweb,代码行数:22,代码来源:views.py


注:本文中的django.core.mail.EmailMultiAlternatives方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。