python类EmailMultiAlternatives()的实例源码

emails.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def send_invite_to_create_account(invitation):
    plaintext = get_template('email-invite.txt')
    htmly = get_template('email-invite.html')
    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "CODE": invitation.code,
               "URL": invitation.url(),
               "EMAIL": invitation.email,
               }

    subject = '[%s] Invitation Code: %s' % (settings.APPLICATION_TITLE,
                                            invitation.code)
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = invitation.email
    text_content = plaintext.render(context)
    html_content = htmly.render(context)
    msg = EmailMultiAlternatives(
        subject, text_content, from_email, [
            to_email, ])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
emails.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def send_invitation_code_to_user(user_code_invitation):
    plaintext = get_template('email-user-code-by-email.txt')
    htmly = get_template('email-user-code-by-email.html')
    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "CODE": user_code_invitation.code,
               "URL": user_code_invitation.url(),
               "EMAIL": user_code_invitation.email}
    subject = '[%s] Invitation Code: %s' % (settings.APPLICATION_TITLE,
                                            user_code_invitation.code)
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = user_code_invitation.email
    text_content = plaintext.render(context)
    html_content = htmly.render(context)
    msg = EmailMultiAlternatives(
        subject, text_content, from_email, [
            to_email, ])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
emails.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def send_password_reset_url_via_email(user, reset_key):
    plaintext = get_template('email-password-reset-link.txt')
    htmly = get_template('email-password-reset-link.html')
    subject = '[%s] Link to reset your password' % (settings.APPLICATION_TITLE)
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = user.email
    password_reset_link = '%s%s' % (get_hostname(),
                                    reverse('password_reset_email_verify',
                                            args=(reset_key,)))

    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "FIRST_NAME": user.first_name,
               "LAST_NAME": user.last_name,
               "PASSWORD_RESET_LINK": password_reset_link}
    text_content = plaintext.render(context)
    html_content = htmly.render(context)
    msg = EmailMultiAlternatives(
        subject, text_content, from_email, [
            to_email, ])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
emails.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def send_access_token_notifcation(token):
    plaintext = get_template('email-access-token-granted.txt')
    htmly = get_template('email-access-token-granted.html')
    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "APP_NAME": token.application.name,
               "HOSTNAME": get_hostname()
               }
    subject = '[%s] You just granted access to %s' % (settings.APPLICATION_TITLE,
                                                      token.application.name)
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = token.user.email
    text_content = plaintext.render(context)
    html_content = htmly.render(context)
    msg = EmailMultiAlternatives(
        subject, text_content, from_email, [
            to_email, ])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
common_utils.py 文件源码 项目:metronus 作者: Metronus 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send_mail(subject, email_template_name, recipients, html_email_template_name,
              context, email_from=DEFAULT_FROM_EMAIL):
    """
    Sends an email to someone
    """
    if 'test' in sys.argv:
        return  # Don't send mails if we are testing to prevent spam

    if context['html']:
        body = loader.render_to_string(email_template_name, context)
    else:
        body = email_template_name

    email_message = EmailMultiAlternatives(subject, body, email_from, recipients)
    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(fail_silently=True)
forms.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
mail.py 文件源码 项目:DjangoCMS 作者: farhan711 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def send_mail(subject, txt_template, to, context=None, html_template=None, fail_silently=True):
    """
    Multipart message helper with template rendering.
    """
    site = Site.objects.get_current()

    context = context or {}
    context.update({
        'login_url': "http://%s" % urljoin(site.domain, admin_reverse('index')),
        'title': subject,
    })

    txt_body = render_to_string(txt_template, context)

    message = EmailMultiAlternatives(subject=subject, body=txt_body, to=to)

    if html_template:
        body = render_to_string(html_template, context)
        message.attach_alternative(body, 'text/html')
    message.send(fail_silently=fail_silently)
forms.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
forms.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
forms.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
forms.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
forms.py 文件源码 项目:CSCE482-WordcloudPlus 作者: ggaytan00 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
tasks.py 文件源码 项目:uwcs-zarya 作者: davidjrichardson 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def mail_newsletter(recipients, mail):
    email_context = {
        'title': mail.subject,
        'message': mail.text,
        'base_url': settings.EMAIL_ABS_URL,
        'sponsors': Sponsor.objects.all(),
    }
    email_html = render_to_string('newsletter/email_newsletter.html', email_context)
    email_plaintext = render_to_string('newsletter/email_newsletter.txt', email_context)
    to = [x.email for x in recipients]
    # Create a map of emails to unsub tokens for the email merge
    unsub_tokens = {recipient.email: {
        'unsub_url': '{hostname}{path}'.format(hostname=settings.EMAIL_ABS_URL,
                                               path=reverse('unsub_with_id', kwargs={
                                                   'token': recipient.unsubscribe_token
                                               }))} for recipient in recipients}
    sender = '{name} <{email}>'.format(name=mail.sender_name, email=mail.sender_email)

    email = EmailMultiAlternatives(mail.subject, email_plaintext, sender, to)
    email.attach_alternative(email_html, 'text/html')
    email.merge_data = unsub_tokens
    email.send()


# Create a function called "chunks" with two arguments, l and n:
rental_create_view.py 文件源码 项目:verleihtool 作者: verleihtool 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def send_confirmation_mail(self, request, rental):
        subject = ('[Verleihtool] Your rental request, %s %s' %
                   (rental.firstname, rental.lastname))
        message = render_to_string('rental/mails/confirmation.md', {
            'rental': rental
        }, request)

        email = EmailMultiAlternatives(
            subject=subject,
            body=message,
            to=[rental.email],
            cc=settings.CC_EMAIL,
        )

        email.attach_alternative(markdown.markdown(message), 'text/html')

        email.send()
forms.py 文件源码 项目:producthunt 作者: davidgengler 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
forms.py 文件源码 项目:django-rtc 作者: scifiswapnil 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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()


问题


面经


文章

微信
公众号

扫码关注公众号