python类DEFAULT_FROM_EMAIL的实例源码

emails.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 22 收藏 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 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def send_activation_key_via_email(user, signup_key):
    """Do not call this directly.  Instead use create_signup_key in utils."""
    plaintext = get_template('email-activate.txt')
    htmly = get_template('email-activate.html')
    subject = '[%s] Verify your email to complete account signup' % (
        settings.APPLICATION_TITLE)
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = user.email
    activation_link = '%s%s' % (get_hostname(),
                                reverse('activation_verify',
                                        args=(signup_key,)))
    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "FIRST_NAME": user.first_name,
               "LAST_NAME": user.last_name,
               "ACTIVATION_LINK": activation_link}
    subject = '[%s] Verify your email to complete your account setup.' % (
        settings.APPLICATION_TITLE)
    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 项目源码 文件源码 阅读 25 收藏 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()
test_tasks.py 文件源码 项目:telemetry-analysis-service 作者: mozilla 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_send_expiration_mails(mailoutbox, mocker, now, cluster_factory):
    cluster = cluster_factory(
        expires_at=now + timedelta(minutes=59),  # 1 hours is the cut-off
        most_recent_status=models.Cluster.STATUS_WAITING,
    )
    assert len(mailoutbox) == 0
    tasks.send_expiration_mails()
    assert len(mailoutbox) == 1
    message = mailoutbox[0]
    assert message.subject == (
        '%sCluster %s is expiring soon!' %
        (settings.EMAIL_SUBJECT_PREFIX, cluster.identifier)
    )
    assert message.from_email == settings.DEFAULT_FROM_EMAIL
    assert list(message.to) == [cluster.created_by.email]
    cluster.refresh_from_db()
    assert cluster.expiration_mail_sent
models.py 文件源码 项目:bryn 作者: MRC-CLIMB 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def new_registration_admin_email(self):
        if not settings.NEW_REGISTRATION_ADMIN_EMAILS:
            return
        context = {'user': self.creator, 'team': self}
        subject = render_to_string(
            'userdb/email/new_registration_admin_subject.txt', context)
        text_content = render_to_string(
            'userdb/email/new_registration_admin_email.txt', context)
        html_content = render_to_string(
            'userdb/email/new_registration_admin_email.html', context)

        send_mail(
            subject,
            text_content,
            settings.DEFAULT_FROM_EMAIL,
            settings.NEW_REGISTRATION_ADMIN_EMAILS,
            html_message=html_content,
            fail_silently=True
        )
models.py 文件源码 项目:bryn 作者: MRC-CLIMB 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def verify_and_send_notification_email(self):
        context = {'user': self.creator, 'team': self}
        subject = render_to_string(
            'userdb/email/notify_team_verified_subject.txt', context)
        text_content = render_to_string(
            'userdb/email/notify_team_verified_email.txt', context)
        html_content = render_to_string(
            'userdb/email/notify_team_verified_email.html', context)

        send_mail(
            subject,
            text_content,
            settings.DEFAULT_FROM_EMAIL,
            [self.creator.email],
            html_message=html_content,
            fail_silently=False
        )

        self.verified = True
        self.save()
models.py 文件源码 项目:bryn 作者: MRC-CLIMB 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send_invitation(self, user):
        self.made_by = user
        self.accepted = False
        self.save()

        context = {'invitation': self,
                   'url': reverse('user:accept-invite', args=[self.uuid])}
        subject = render_to_string(
            'userdb/email/user_invite_subject.txt', context)
        text_content = render_to_string(
            'userdb/email/user_invite_email.txt', context)
        html_content = render_to_string(
            'userdb/email/user_invite_email.html', context)

        send_mail(
            subject,
            text_content,
            settings.DEFAULT_FROM_EMAIL,
            [self.email],
            html_message=html_content,
            fail_silently=False
        )
models.py 文件源码 项目:bryn 作者: MRC-CLIMB 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def send_validation_link(self, user):
        self.user = user
        self.email_validated = False
        self.save()

        context = {'user': user,
                   'validation_link': reverse('user:validate-email',
                                              args=[self.validation_link])}
        subject = render_to_string(
            'userdb/email/user_verification_subject.txt', context)
        text_content = render_to_string(
            'userdb/email/user_verification_email.txt', context)
        html_content = render_to_string(
            'userdb/email/user_verification_email.html', context)

        send_mail(
            subject,
            text_content,
            settings.DEFAULT_FROM_EMAIL,
            [user.email],
            html_message=html_content,
            fail_silently=False
        )
admin.py 文件源码 项目:organizer 作者: tdfischer 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def email_view(self, request, action_id):
        action = models.Action.objects.get(pk=action_id)
        if request.method == 'POST':
            email_form = forms.EmailForm(request.POST)
            if email_form.is_valid():
                email_template = loader.get_template('email.eml')
                signups = action.signups.filter(state=email_form.cleaned_data['to'])
                for s in signups:
                    generated_email = email_template.render({'signup': s,
                        'body': email_form.cleaned_data['body']})
                    send_mail(email_form.cleaned_data['subject'],
                            generated_email,
                    settings.DEFAULT_FROM_EMAIL,
                    [s.activist.email])
            messages.success(request, '%s emails sent!' % (len(signups)))
        else:
            email_form = forms.EmailForm()

        context = dict(
            self.admin_site.each_context(request),
            action=action,
            form=email_form
        )
        return render(request, 'admin_email.html', context)
models.py 文件源码 项目:omni-forms 作者: omni-digital 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle(self, form):
        """
        Handle method
        Sends an email to the specified recipients

        :param form: Valid form instance
        :type form: django.forms.Form
        """
        message = EmailMessage(
            self.subject,
            self._render_template(form.cleaned_data),
            settings.DEFAULT_FROM_EMAIL,
            self.recipients.split(',')
        )

        for file_object in self.get_files(form):
            message.attach(file_object.name, file_object.read(), file_object.content_type)

        message.send()
moderation.py 文件源码 项目:tissuelab 作者: VirtualPlants 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def email(self, comment, content_object, request):
        """
        Send email notification of a new comment to site staff when email
        notifications have been requested.

        """
        if not self.email_notification:
            return
        recipient_list = [manager_tuple[1] for manager_tuple in settings.MANAGERS]
        t = loader.get_template('comments/comment_notification_email.txt')
        c = Context({ 'comment': comment,
                      'content_object': content_object })
        subject = '[%s] New comment posted on "%s"' % (get_current_site(request).name,
                                                          content_object)
        message = t.render(c)
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True)
veranstalter.py 文件源码 项目:pyfeedback 作者: d120 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def send_mail_to_verantwortliche(ergebnis_empfaenger, context, veranstaltung):
    """
    Sendet eine Email an die Ergebnis-Empfaenger mit der Zusammenfassung der Bestellung.
    :param ergebnis_empfaenger: Empfänger der Ergebnisse
    :param context: E-Mail Inhalt
    :param veranstaltung: Veranstaltung
    """
    if context.get('tutoren_csv', None) is not None:
        tutoren = Tutor.objects.filter(veranstaltung=veranstaltung)
        context.update({'tutoren': tutoren})

    msg_html = render_to_string('formtools/wizard/email_zusammenfassung.html', context)

    if ergebnis_empfaenger is not None:
        for e in ergebnis_empfaenger:
            send_mail(
                'Evaluation der Lehrveranstaltungen - Zusammenfassung der Daten',
                'Nachfolgend finder Sie Informationen zu Ihrer Bestellung',
                settings.DEFAULT_FROM_EMAIL,
                [e.email],
                html_message=msg_html,
                fail_silently=False,
            )
views.py 文件源码 项目:django-learning 作者: adoggie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def send_activation_email(self, user):
        """
        Send the activation email. The activation key is simply the
        username, signed using TimestampSigner.

        """
        activation_key = self.get_activation_key(user)
        context = self.get_email_context(activation_key)
        context.update({
            'user': user
        })
        subject = render_to_string(self.email_subject_template,
                                   context)
        # Force subject to a single line to avoid header-injection
        # issues.
        subject = ''.join(subject.splitlines())
        message = render_to_string(self.email_body_template,
                                   context)
        user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
models.py 文件源码 项目:django-learning 作者: adoggie 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def send_activation_email(self, site):
        """
        Send an activation email to the user associated with this
        ``RegistrationProfile``.

        """
        ctx_dict = {'activation_key': self.activation_key,
                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                    'user': self.user,
                    'site': site}
        subject = render_to_string('registration/activation_email_subject.txt',
                                   ctx_dict)
        # Force subject to a single line to avoid header-injection
        # issues.
        subject = ''.join(subject.splitlines())

        message = render_to_string('registration/activation_email.txt',
                                   ctx_dict)

        self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
models.py 文件源码 项目:alterchef 作者: libremesh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _process(self, *args, **kwargs):
        output = u"%s\n" % self.job_data
        job_url = reverse('fwjob-detail', kwargs={'pk': self.pk})
        domain = Site.objects.all()[0].domain

        for command in self.job_data["commands"]:
            output += command + "\n"
            p = subprocess.Popen(command.split(), stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
            output += p.communicate()[0].decode("utf-8")

            if p.returncode != 0:
                email_msg = "Cook failed for job http://%s%s" % (domain, job_url)
                mail_managers("[Chef] Cook failed", email_msg, fail_silently=True)
                send_mail("[Chef] Cook failed", email_msg, settings.DEFAULT_FROM_EMAIL,
                          [self.user.email], fail_silently=True)
                self.status = "FAILED"
                self.build_log = output
                self.save()
                return
        email_msg = "Cook finished: http://%s%s" % (domain, job_url)
        send_mail("[Chef] Cook finished", email_msg, settings.DEFAULT_FROM_EMAIL,
                  [self.user.email], fail_silently=True)
        self.status = "FINISHED"
        self.save()
models.py 文件源码 项目:helios-server-mixnet 作者: RunasSudo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def generate_trustee(self, params):
    """
    generate a trustee including the secret key,
    thus a helios-based trustee
    """
    # FIXME: generate the keypair
    keypair = params.generate_keypair()

    # create the trustee
    trustee = Trustee(election = self)
    trustee.uuid = str(uuid.uuid4())
    trustee.name = settings.DEFAULT_FROM_NAME
    trustee.email = settings.DEFAULT_FROM_EMAIL
    trustee.public_key = keypair.pk
    trustee.secret_key = keypair.sk

    # FIXME: is this at the right level of abstraction?
    trustee.public_key_hash = datatypes.LDObject.instantiate(trustee.public_key, datatype='legacy/EGPublicKey').hash

    trustee.pok = trustee.secret_key.prove_sk(algs.DLog_challenge_generator)

    trustee.save()
    return trustee
notification.py 文件源码 项目:assethub 作者: portnov 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def process(instance, parent, created):
        for info in Event.get(instance, parent, created):
            for recipient in info.recipients:
                if recipient == info.actor:
                    continue
                print("Notify {0} about {1} {2}".format(recipient, instance, info.verb))
                notify.send(info.actor, verb=info.verb, action_object=instance, target=parent, recipient=recipient, template=info.template_name, url=info.url)
                if info.is_user_subscribed(recipient):
                    subject = info.email_subject
                    template = loader.get_template(join('assets', 'notification', info.email_body_template))
                    context = info.email_context
                    context['user'] = recipient
                    body = template.render(context)
                    if subject and body:
                        print("Send mail to {0}: {1}".format(recipient.email, subject).encode('utf-8'))
                        send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [recipient.email], fail_silently = False)

### Specific events


问题


面经


文章

微信
公众号

扫码关注公众号