Python django.conf.settings 模块,DEFAULT_FROM_EMAIL 实例源码

我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用django.conf.settings.DEFAULT_FROM_EMAIL

项目:Bitpoll    作者:fsinfuhh    | 项目源码 | 文件源码
def _send_invitation_mail(request, invitation, subject, template_name):
    if not invitation.invitee.email:
        return
    old_lang = translation.get_language()
    translation.activate(invitation.invitee.language)
    template = loader.get_template('groups/mail_{0}.txt'.format(template_name))
    message = template.render({
        'invitation': invitation,
        'site': get_current_site(request)
    })
    translation.activate(old_lang)
    send_mail(settings.EMAIL_SUBJECT_PREFIX + subject,
              message,
              settings.DEFAULT_FROM_EMAIL,
              [invitation.invitee.email],
              fail_silently=True)
项目:mk42    作者:Peer-Lab    | 项目源码 | 文件源码
def email_context(self):
        """
        Return user emails default context.

        :return: default context for user emails.
        :rtype: dict.
        """

        return {
            "user": self,
            "site": Site.objects.get_current(),
            "FROM_EMAIL": settings.DEFAULT_FROM_EMAIL,
            "FROM_EMAIL_SENDER": settings.DEFAULT_FROM_EMAIL_SENDER,
            "FROM": "{sender} <{email}>".format(**{
                "sender": settings.DEFAULT_FROM_EMAIL_SENDER,
                "email": settings.DEFAULT_FROM_EMAIL,
            }),
            "protocol": settings.URL_PROTOCOL,
        }
项目:mk42    作者:Peer-Lab    | 项目源码 | 文件源码
def send_email(self, template, context):
        """
        Send email to user.

        :param template: email template.
        :type template: unicode.
        :param context: email context.
        :type context: dict.
        """

        context.update(self.email_context)  # update email context by some default values
        language = get_language()  # remember current language (sometimes it's useful)
        activate(self.language)
        send_templated_mail(
            template_name=template,
            from_email=context.get("FROM", settings.DEFAULT_FROM_EMAIL),
            recipient_list=[self.email, ],
            context=context,
        )
        activate(language)
项目:pyconjp-website    作者:pyconjp    | 项目源码 | 文件源码
def send_email(to, kind, **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("emails/%s/subject.txt" % kind, ctx).strip()
    )

    message_html = render_to_string("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)
    email.attach_alternative(message_html, "text/html")
    email.send()
项目:PublicAPI    作者:InternetSemLimites    | 项目源码 | 文件源码
def provider_new(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST'])

    form = ProviderForm(request.POST)
    if not form.is_valid():
        return JsonResponse({'errors': form.errors})

    provider = form.save()
    _send_mail('+1 InternetSemLimites',
               settings.DEFAULT_FROM_EMAIL,
               list(_get_admin_emails()),
               'core/provider_email.txt',
               dict(provider=provider))

    return HttpResponseRedirect(resolve_url('api:provider', provider.pk))
项目:timed-backend    作者:adfinis-sygroup    | 项目源码 | 文件源码
def _notify_reviewers(self, start, end, reports):
        """Notify reviewers on their unverified reports."""
        User = get_user_model()
        reviewers = User.objects.all_reviewers().filter(email__isnull=False)
        subject = '[Timed] Verification of reports'
        from_email = settings.DEFAULT_FROM_EMAIL
        mails = []

        for reviewer in reviewers:
            if reports.filter(task__project__reviewers=reviewer).exists():
                body = render_to_string(
                    'mail/notify_reviewers_unverified.txt', {
                        # we need start and end date in system format
                        'start': str(start),
                        'end': str(end),
                        'reviewer': reviewer,
                        'protocol': settings.HOST_PROTOCOL,
                        'domain': settings.HOST_DOMAIN,
                    }, using='text'
                )

                mails.append((subject, body, from_email, [reviewer.email]))

        if len(mails) > 0:
            send_mass_mail(mails)
项目:opencon-2016-app-code    作者:sparcopen    | 项目源码 | 文件源码
def send_access(self):
        if self.sent_email_data:
            can_send = timezone.now() - self.sent_email_data > datetime.timedelta(minutes=settings.SEND_ACCESS_INTERVAL)
        else:
            can_send = True

        if can_send:
            self.sent_email_data = timezone.now()
            self.save()
            if settings.SEND_EMAILS:
                message = render_to_string('application/email/draft.txt', {'uuid': self.uuid, 'email': self.email,})
                email = EmailMessage(
                    subject='OpenCon 2016 Draft Application',
                    body=message,
                    from_email=settings.DEFAULT_FROM_EMAIL,
                    to=[self.email],
                )
                email.content_subtype = "html"
                email.send(fail_silently=True)
            return True
        return False
项目:Try-Django-1.11    作者:codingforentrepreneurs    | 项目源码 | 文件源码
def send_activation_email(self):
        if not self.activated:
            self.activation_key = code_generator()# 'somekey' #gen key
            self.save()
            #path_ = reverse()
            path_ = reverse('activate', kwargs={"code": self.activation_key})
            full_path = "https://muypicky.com" + path_
            subject = 'Activate Account'
            from_email = settings.DEFAULT_FROM_EMAIL
            message = f'Activate your account here: {full_path}'
            recipient_list = [self.user.email]
            html_message = f'<p>Activate your account here: {full_path}</p>'
            print(html_message)
            sent_mail = send_mail(
                            subject, 
                            message, 
                            from_email, 
                            recipient_list, 
                            fail_silently=False, 
                            html_message=html_message)
            sent_mail = False
            return sent_mail
项目:steemprojects.com    作者:noisy    | 项目源码 | 文件源码
def handle(self, *args, **options): 
        print("Commencing big email send", file=stdout)

        #users = User.objects.filter(is_active=True).exclude(email__contains="qq.com").exclude(email__contains="tom.com")
        users = User.objects.filter(username__in=("pydanny","audreyr"))

        for index, user in enumerate(users):
            if not user.email.strip():
                continue
            send_mail(
                subject=settings.BIG_EMAIL_SEND_SUBJECT,
                message=settings.BIG_EMAIL_SEND,
                from_email=settings.DEFAULT_FROM_EMAIL,
                recipient_list=[user.email,],
            )            
            print("Sent to", index, user.email)
            time.sleep(1)
项目:Quantrade    作者:quant-trade    | 项目源码 | 文件源码
def send_broker_notifications(logged_user):
    try:
        if logged_user.email:
            recipients = [logged_user.email]
            subject = "Quantrade received your broker account"
            message = "We had received your broker account number. In a day, your acount will be checked and activated by robot.\n\n"
            sender = settings.DEFAULT_FROM_EMAIL
            send_mail(subject, message, sender, recipients)

        recipients = [settings.NOTIFICATIONS_EMAILS]
        subject = "New user registered broekr account"
        message = "User: {1}.\n\n".format(logged_user.username)
        sender = settings.DEFAULT_FROM_EMAIL
        send_mail(subject, message, sender, recipients)
    except:
        pass
项目:Quantrade    作者:quant-trade    | 项目源码 | 文件源码
def data_checker(loop):
    list_failing = []
    p = join(settings.DATA_PATH, "incoming")
    filenames = multi_filenames(path_to_history=p, csv=True)

    list_failing = read_failing(filenames=filenames, path_to=p, loop=loop, list_failing=list_failing)

    if settings.SHOW_DEBUG:
        print("Failing symbols: {}\n".format(list_failing))

    cnt = len(list_failing)
    print("Failing number: {}\n".format(cnt))

    if (cnt > 0) & (cnt < 10):
        subject = "Failing datafiles: {}".format(cnt)
        message = "{0}\n\n".format(list_failing)
        sender = settings.DEFAULT_FROM_EMAIL
        send_mail(subject, message, sender, settings.NOTIFICATIONS_EMAILS)

        loop.run_until_complete(gather(*[clean_failed_file(path_to=p, \
            file_name=file_name) for file_name in list_failing], return_exceptions=True
        ))
项目:Quantrade    作者:quant-trade    | 项目源码 | 文件源码
def send_new_profile_email(sender, instance, **kwargs):
    try:
        if kwargs["created"]:
            send_mail('New user registered at Quantrade', \
                'Quantrade has new user {}.\n\n'.format(instance), \
                settings.DEFAULT_FROM_EMAIL,
                settings.NOTIFICATIONS_EMAILS, \
                fail_silently=False)

            email = instance.email
            if email:
                send_mail('You had registered at Quantrade!', \
                    'You are now the member of Quantrade quantitative trading signals where you can enjoy hundreds of profitable trading strategies for free!.\n\n', \
                    settings.DEFAULT_FROM_EMAIL,
                    [email], \
                    fail_silently=False)

    except:
        pass
项目:teamreporter    作者:agilentia    | 项目源码 | 文件源码
def send_summary(report_pk):
    report = Report.objects.get(pk=report_pk)
    daily = report.get_daily()
    messages = []
    questions = daily.report.question_set.active()
    surveys = daily.survey_set.all()
    for user in report.stakeholders:
        context = Context({'user': user,
                           'daily': daily,
                           'surveys': surveys,
                           'questions': questions})
        context['SITE_URL'] = settings.SITE_URL
        subject = render_to_string('email/summary_subject.txt', context)

        text = get_template('email/summary.txt')
        html = get_template('email/summary.html')
        text_content = text.render(context)
        html_content = html.render(context)
        messages.append([subject, text_content, html_content, settings.DEFAULT_FROM_EMAIL, [user.email]])

    send_mass_html_mail(messages)
    daily.summary_submitted = now()
    daily.save()
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def send(request, receivers, subject, message, fail_silently=True):
    if not receivers:
        return True
    if isinstance(receivers, str):
        receivers = [receivers]

    # ??????? ?????? ? subject
    site = get_current_site(request)
    subject = subject.format(domain=site.domain)

    plain = strip_tags(message)
    plain = re_newline_spaces.sub('\n', plain)
    plain = re_newlines.sub('\n\n', plain)

    send_mail(
        subject=subject,
        message=plain,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=receivers,
        html_message=message,
        fail_silently=fail_silently,
    )
项目:QProb    作者:quant-trade    | 项目源码 | 文件源码
def send_new_feedback_email(sender, instance, **kwargs):
    try:
        if kwargs["created"]:
            send_mail('New feedback at {}'.format(settings.SHORT_SITE_NAME), \
                'The message {0}.\n\nName: {1}\n\nEmail: {2}'.format(instance.message, instance.name, instance.email), \
                settings.DEFAULT_FROM_EMAIL,
                settings.NOTIFICATIONS_EMAILS, \
                fail_silently=False)

            email = instance.email
            if email:
                send_mail('Thank you for your feedback for {}!'.format(settings.SHORT_SITE_NAME), \
                    "Thank you for your mesasge. If requested, we'll contact you shortly.\n\n", \
                    settings.DEFAULT_FROM_EMAIL,
                    [email], \
                    fail_silently=False)

    except:
        pass
项目:QProb    作者:quant-trade    | 项目源码 | 文件源码
def send_new_source_email(sender, instance, **kwargs):
    try:
        if kwargs["created"]:
            send_mail('New source at {}'.format(settings.SHORT_SITE_NAME), \
                'New source registered, pelase visit to review.', \
                settings.DEFAULT_FROM_EMAIL,
                settings.NOTIFICATIONS_EMAILS, \
                fail_silently=False)

            email = instance.email
            if email:
                send_mail('Thank you for your addition in {}!'.format(settings.SHORT_SITE_NAME), \
                    "Thank you for your resource registration. We'll include it shortly if not yet and appropriate.\n\n", \
                    settings.DEFAULT_FROM_EMAIL,
                    [email], \
                    fail_silently=False)

    except:
        pass
项目:simple-django-login-and-register    作者:egorsmkv    | 项目源码 | 文件源码
def send_activation_email(request, user):
    subject = _('Profile Activation')

    from_email = settings.DEFAULT_FROM_EMAIL
    current_site = get_current_site(request)
    domain = current_site.domain
    code = get_random_string(20)

    context = {
        'domain': domain,
        'code': code,
    }

    act = Activation()
    act.code = code
    act.user = user
    act.save()

    html_content = render_to_string('email/activation_profile.html', context=context, request=request)
    text_content = strip_tags(html_content)

    msg = EmailMultiAlternatives(subject, text_content, from_email, [user.email])
    msg.attach_alternative(html_content, 'text/html')
    msg.send()
项目:simple-django-login-and-register    作者:egorsmkv    | 项目源码 | 文件源码
def send_activation_change_email(request, user, new_email):
    subject = _('Change email')

    from_email = settings.DEFAULT_FROM_EMAIL
    current_site = get_current_site(request)
    domain = current_site.domain
    code = get_random_string(20)

    context = {
        'domain': domain,
        'code': code,
    }

    act = Activation()
    act.code = code
    act.user = user
    act.email = new_email
    act.save()

    html_content = render_to_string('email/change_email.html', context=context, request=request)
    text_content = strip_tags(html_content)

    msg = EmailMultiAlternatives(subject, text_content, from_email, [user.email])
    msg.attach_alternative(html_content, 'text/html')
    msg.send()
项目:simple-django-login-and-register    作者:egorsmkv    | 项目源码 | 文件源码
def send_reset_password_email(request, user):
    from_email = settings.DEFAULT_FROM_EMAIL
    current_site = get_current_site(request)
    site_name = current_site.name
    domain = current_site.domain

    token_generator = default_token_generator
    use_https = request.is_secure()

    context = {
        'email': user.email,
        'domain': domain,
        'site_name': site_name,
        'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
        'user': user,
        'token': token_generator.make_token(user),
        'protocol': 'https' if use_https else 'http',
    }

    subject = loader.render_to_string('registration/password_reset_subject.txt', context)
    subject = ''.join(subject.splitlines())
    body = loader.render_to_string('registration/password_reset_email.html', context)

    email_message = EmailMultiAlternatives(subject, body, from_email, [user.email])
    email_message.send()
项目:SaBoT    作者:froscon    | 项目源码 | 文件源码
def change_notification(self, changed_fields):
        if len(changed_fields) == 0:
            return
        change_dict = {}
        for field in changed_fields:
            field_name = self.object.fieldDescriptionalNames.get(field,field)
            change_dict[field_name] = getattr(self.object,field)

        ctx_dict = {
            "sponsor" : self.object,
            "change_dict" : change_dict,
            "user" : self.request.user,
        }
        subject = "Sponsor information change notification"
        message = render_to_string('sponsor/change_notification_email.txt', ctx_dict)
        send_mail(subject,message,settings.DEFAULT_FROM_EMAIL,settings.SPONSOR_NOTIFICATION,fail_silently=True)

        if "clearedForBilling" in changed_fields and self.object.clearedForBilling == True:
            subject = "Sponsoring ready for billing"
            message = render_to_string('sponsor/ready_for_billing_notification_email.txt', ctx_dict)
            send_mail(subject,message,settings.DEFAULT_FROM_EMAIL,settings.FINANCE_EMAIL,fail_silently=True)
项目:SaBoT    作者:froscon    | 项目源码 | 文件源码
def send_info_email(self, user):
        profile = RegistrationProfile.objects.get(user=user)
        site = Site.objects.get_current()

        ctx_dict = {'activation_key': profile.activation_key,
            'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
            'install_main_url' : settings.INSTALL_MAIN_URL,
            'conference_name' : settings.CONFERENCE_NAME,
            'site': site,
            'project' : self.object,
            'user' : user}
        subject = render_to_string('registration/activation_email_autocreate_subject.txt', ctx_dict)
        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())

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

        user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
项目:ecs    作者:ecs-org    | 项目源码 | 文件源码
def send_protocol(request, meeting_pk=None):
    meeting = get_object_or_404(Meeting, ended__isnull=False,
        protocol_sent_at=None, pk=meeting_pk)

    meeting.protocol_sent_at = timezone.now()
    meeting.save()

    protocol_pdf = meeting.protocol.retrieve_raw().read()
    attachments = (
        (meeting.protocol.original_file_name, protocol_pdf, 'application/pdf'),
    )

    for user in User.objects.filter(Q(meeting_participations__entry__meeting=meeting) | Q(groups__name__in=settings.ECS_MEETING_PROTOCOL_RECEIVER_GROUPS)).distinct():
        htmlmail = str(render_html(request, 'meetings/messages/protocol.html', {'meeting': meeting, 'recipient': user}))
        deliver(user.email, subject=_('Meeting Protocol'), message=None,
            message_html=htmlmail, from_email=settings.DEFAULT_FROM_EMAIL,
            attachments=attachments)

    return redirect('ecs.meetings.views.meeting_details', meeting_pk=meeting.pk)
项目:ecs    作者:ecs-org    | 项目源码 | 文件源码
def register(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        token = _registration_token_factory.generate_token(form.cleaned_data)
        activation_url = request.build_absolute_uri(reverse('ecs.users.views.activate', kwargs={'token': token}))        
        htmlmail = str(render_html(request, 'users/registration/activation_email.html', {
            'activation_url': activation_url,
            'form': form,
        }))
        deliver(form.cleaned_data['email'], subject=_('ECS - Registration'), message=None, message_html=htmlmail,
            from_email= settings.DEFAULT_FROM_EMAIL, nofilter=True)
        return render(request, 'users/registration/registration_complete.html', {})

    return render(request, 'users/registration/registration_form.html', {
        'form': form,
    })
项目:festcms    作者:NITDgpOS    | 项目源码 | 文件源码
def subscribe(request):
    context = {}

    if request.method == 'POST':
        form = SubscriptionForm(request.POST)
        to_addr = request.POST.get('contact_email', '')
        if Subscription.objects.filter(contact_email=to_addr).count():
            context['result'] = ('Your email: %s has already'
                                 ' been subscribed.' % to_addr)
        elif form.is_valid():
            form.save()
            send_subscription_success(
                from_addr=settings.DEFAULT_FROM_EMAIL,
                to_addr=to_addr,
                template='subscribed_email',)
            context['result'] = ('Your email: %s is successfully'
                                 ' subscribed.' % to_addr)
    else:
        form = SubscriptionForm
        context['subscription_form'] = form
        id = request.GET.get('unsubscribe', '')
        if len(id) != 0:
            context['unsubscribe'] = unsubscribe(id)

    return render(request, 'festflow/subscribe.html', context)
项目:festcms    作者:NITDgpOS    | 项目源码 | 文件源码
def send_email(modeladmin, request, queryset):
    our_email = settings.DEFAULT_FROM_EMAIL
    users = Subscription.objects.all()
    recipients = [user.contact_email for user in users]
    messages = []
    site = get_current_site(request)
    template = get_template('festflow/newsletter.html')
    for user in users:
        for newsletter in queryset:
            content = template.render({
                'newsletter': newsletter.content,
                'url': 'http://%s/subscribe?unsubscribe=%s' % (
                    site, user.identifier),
            })
            messages.append((
                "Newsletter",
                content,
                our_email,
                recipients))

    send_mass_mail(messages, fail_silently=False)
项目:django-simple-forum    作者:MicroPyramid    | 项目源码 | 文件源码
def form_valid(self, form):
        user = User.objects.filter(email=self.request.POST.get('email'))
        if user:
            user = user[0]
            subject = "Password Reset"
            password = get_random_string(6)
            message = '<p>Your Password for the forum account is <strong>'+password + \
                '</strong></p><br/><p>Use this credentials to login into <a href="' + \
                settings.HOST_URL + '/forum/">forum</a></p>'
            to = user.email
            from_email = settings.DEFAULT_FROM_EMAIL
            Memail([to], from_email, subject, message, email_template_name=None, context=None)
            user.set_password(password)
            user.save()
            data = {
                "error": False, "response": "An Email is sent to the entered email id"}
            return JsonResponse(data)
        else:
            data = {
                "error": True, "message": "User With this email id doesn't exists!!!"}
            return JsonResponse(data)
项目:knowledge-base    作者:Axiacore    | 项目源码 | 文件源码
def form_valid(self, form):
        email = form.cleaned_data['email']
        user = User.objects.get(username=email)
        safe = URLSafeTimedSerializer(settings.SECRET_KEY)
        url = '{site}{path}?key={key}'.format(
            site=settings.SITE_URL,
            path=reverse('login'),
            key=safe.dumps(user.id),
        )

        send_mail(
            _('Link to login into the Knowledge Base'),
            url,
            settings.DEFAULT_FROM_EMAIL,
            [email],
            fail_silently=False,
            html_message=render_to_string(
                'login_email.html', {'url': url}
            ),
        )

        return redirect('home')
项目:securethenews    作者:freedomofpress    | 项目源码 | 文件源码
def send_confirmation_email(request, pledge):
    assert not pledge.confirmed, "{} is already confirmed"

    subject = "Confirm your pledge to secure your site"

    confirmation_link = request.build_absolute_uri("{}?{}".format(
        reverse('pledges:confirm', kwargs={'pk': pledge.pk}),
        urlencode({'nonce': pledge.confirmation_nonce})
    ))

    message = render_to_string('pledges/emails/confirmation.txt', {
        'confirmation_link': confirmation_link
    })

    send_mail(
        subject=subject,
        message=message,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[pledge.contact_email, ]
    )
项目:bluebutton-web-server    作者:CMSgov    | 项目源码 | 文件源码
def notify_admin_of_invite_request(request_invite):
    plaintext = get_template('email-invite-request-received.txt')
    htmly = get_template('email-invite-request-received.html')
    context = {"APPLICATION_TITLE": settings.APPLICATION_TITLE,
               "EMAIL": request_invite.email,
               "FIRST_NAME": request_invite.first_name,
               "LAST_NAME": request_invite.last_name,
               "USER_TYPE": request_invite.user_type
               }
    subject = '[%s] Request for %s access from : %s %s' % (settings.APPLICATION_TITLE,
                                                           request_invite.user_type,
                                                           request_invite.first_name,
                                                           request_invite.last_name)
    from_email = settings.DEFAULT_FROM_EMAIL
    if settings.DEFAULT_FROM_EMAIL == settings.DEFAULT_ADMIN_EMAIL:
        to_email = [settings.DEFAULT_ADMIN_EMAIL]
    else:
        to_email = [settings.DEFAULT_ADMIN_EMAIL, settings.DEFAULT_FROM_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()
项目:bluebutton-web-server    作者:CMSgov    | 项目源码 | 文件源码
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()
项目:bluebutton-web-server    作者:CMSgov    | 项目源码 | 文件源码
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()
项目:bluebutton-web-server    作者:CMSgov    | 项目源码 | 文件源码
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()
项目:bluebutton-web-server    作者:CMSgov    | 项目源码 | 文件源码
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()
项目:telemetry-analysis-service    作者:mozilla    | 项目源码 | 文件源码
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
项目:bryn    作者:MRC-CLIMB    | 项目源码 | 文件源码
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
        )
项目:bryn    作者:MRC-CLIMB    | 项目源码 | 文件源码
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()
项目:bryn    作者:MRC-CLIMB    | 项目源码 | 文件源码
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
        )
项目:bryn    作者:MRC-CLIMB    | 项目源码 | 文件源码
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
        )
项目:organizer    作者:tdfischer    | 项目源码 | 文件源码
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)
项目:omni-forms    作者:omni-digital    | 项目源码 | 文件源码
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()
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
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)
项目:pyfeedback    作者:d120    | 项目源码 | 文件源码
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,
            )
项目:django-learning    作者:adoggie    | 项目源码 | 文件源码
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)
项目:django-learning    作者:adoggie    | 项目源码 | 文件源码
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)
项目:alterchef    作者:libremesh    | 项目源码 | 文件源码
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()
项目:helios-server-mixnet    作者:RunasSudo    | 项目源码 | 文件源码
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
项目:assethub    作者:portnov    | 项目源码 | 文件源码
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