Python django.core.mail 模块,mail_admins() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用django.core.mail.mail_admins()

项目:wger-lycan-clan    作者:andela    | 项目源码 | 文件源码
def form_valid(self, form):
        '''
        If the form is valid send email notifications to the site administrators.

        We don't return the super().form_valid because we don't want the data
        to be saved.
        '''
        subject = 'Correction submitted for exercise #{0}'.format(self.get_object().pk)
        context = {
            'exercise': self.get_object(),
            'form_data': form.cleaned_data,
            'user': self.request.user
        }
        message = render_to_string('exercise/email_correction.tpl', context)
        mail.mail_admins(six.text_type(subject),
                         six.text_type(message),
                         fail_silently=True)

        messages.success(self.request, self.messages)
        return HttpResponseRedirect(reverse('exercise:exercise:view',
                                            kwargs={'id': self.object.id}))
项目:wger-lycan-clan    作者:andela    | 项目源码 | 文件源码
def set_author(self, request):
        '''
        Set author and status

        This is only used when creating exercises (via web or API)
        '''
        if request.user.has_perm('exercises.add_exercise'):
            self.status = self.STATUS_ACCEPTED
            if not self.license_author:
                self.license_author = request.get_host().split(':')[0]
        else:
            if not self.license_author:
                self.license_author = request.user.username

            subject = _('New user submitted exercise')
            message = _(u'The user {0} submitted a new exercise "{1}".').format(
                request.user.username, self.name)
            mail.mail_admins(six.text_type(subject),
                             six.text_type(message),
                             fail_silently=True)
项目:wger-lycan-clan    作者:andela    | 项目源码 | 文件源码
def set_author(self, request):
        '''
        Set author and status

        This is only used when creating images (via web or API)
        '''
        if request.user.has_perm('exercises.add_exerciseimage'):
            self.status = self.STATUS_ACCEPTED
            if not self.license_author:
                self.license_author = request.get_host().split(':')[0]

        else:
            if not self.license_author:
                self.license_author = request.user.username

            subject = _('New user submitted image')
            message = _(u'The user {0} submitted a new image "{1}" for exercise {2}.').format(
                request.user.username,
                self.name,
                self.exercise)
            mail.mail_admins(six.text_type(subject),
                             six.text_type(message),
                             fail_silently=True)
项目:wger-lycan-clan    作者:andela    | 项目源码 | 文件源码
def form_valid(self, form):

        # set the submitter, if admin, set approrpiate status
        form.instance.user = self.request.user
        if self.request.user.has_perm('nutrition.add_ingredient'):
            form.instance.status = Ingredient.INGREDIENT_STATUS_ADMIN
        else:
            subject = _('New user submitted ingredient')
            message = _(u'''The user {0} submitted a new ingredient "{1}".'''.format(
                        self.request.user.username, form.instance.name))
            mail.mail_admins(subject,
                             message,
                             fail_silently=True)

        form.instance.language = load_language()
        return super(IngredientCreateView, self).form_valid(form)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
项目:edd    作者:JBEI    | 项目源码 | 文件源码
def mail_admins(subject, message, *args, **kwargs):  # noqa
    """
    Wraps the mail_admins function from Django to wrap long lines in emails. The exim mail server
    used in EDD dis-allows lines longer than 998 bytes.
    """
    wrapper = TextWrapper(width=79, break_on_hyphens=False, replace_whitespace=False,
                          subsequent_indent='  ')
    message = '\n'.join(chain(*[wrapper.wrap(line) for line in message.splitlines()]))
    _mail_admins(subject, message, *args, **kwargs)
项目:wger-lycan-clan    作者:andela    | 项目源码 | 文件源码
def form_valid(self, form):
        '''
        Send the feedback to the administrators
        '''
        messages.success(self.request, _('Your feedback was successfully sent. Thank you!'))

        context = {}
        context['user'] = self.request.user
        context['form_data'] = form.cleaned_data

        subject = 'New feedback'
        message = render_to_string('user/email_feedback.html', context)
        mail.mail_admins(subject, message)

        return super(FeedbackClass, self).form_valid(form)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def send_mail(self, subject, message, *args, **kwargs):
        mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)