python类get_connection()的实例源码

message.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
mailutils.py 文件源码 项目:ecs 作者: ecs-org 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def deliver_to_recipient(recipient, subject, message, from_email,
    message_html=None, attachments=None, nofilter=False, rfc2822_headers=None):

    msg = create_mail(subject, message, from_email, recipient, message_html,
        attachments, rfc2822_headers)
    msgid = msg.extra_headers['Message-ID']

    backend = settings.EMAIL_BACKEND
    if nofilter or recipient.split('@')[1] in settings.EMAIL_UNFILTERED_DOMAINS:
        backend = settings.EMAIL_BACKEND_UNFILTERED

    connection = mail.get_connection(backend=backend)
    connection.send_messages([msg])

    return (msgid, msg.message(),)
tasks.py 文件源码 项目:django-danceschool 作者: django-danceschool 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def sendEmail(subject,content,from_address,from_name='',to=[],cc=[],bcc=[],attachment_name='attachment',attachment=None,html_content=None):
    # Ensure that email address information is in list form and that there are no empty values
    recipients = [x for x in to + cc if x]
    bcc = [x for x in bcc if x]
    from_email = from_name + ' <' + from_address + '>' if from_address else None
    reply_to = [from_address,] if from_address else None

    logger.info('Sending email from %s to %s' % (from_address,recipients))

    if getattr(settings,'DEBUG',None):
        logger.info('Email content:\n\n%s' % content)
        logger.info('Email HTML content:\n\n%s' % html_content)

    with get_connection() as connection:
        connection.open()

        message = EmailMultiAlternatives(
            subject=subject,
            body=content,
            from_email=from_email,
            to=recipients,
            bcc=bcc,
            reply_to=reply_to,
            connection=connection,
        )

        if html_content:
            message.attach_alternative(html_content, "text/html")

        if attachment:
            message.attach(attachment_name, attachment)

        message.send(fail_silently=False)
        connection.close()
admin.py 文件源码 项目:heltour 作者: cyanfish 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def bulk_email_view(self, request, object_id):
        season = get_object_or_404(Season, pk=object_id)
        if not request.user.has_perm('tournament.bulk_email', season.league):
            raise PermissionDenied

        if request.method == 'POST':
            form = forms.BulkEmailForm(season.seasonplayer_set.count(), request.POST)
            if form.is_valid() and form.cleaned_data['confirm_send']:
                season_players = season.seasonplayer_set.all()
                email_addresses = {sp.player.email for sp in season_players if sp.player.email != ''}
                email_messages = []
                for addr in email_addresses:
                    message = EmailMultiAlternatives(
                        form.cleaned_data['subject'],
                        form.cleaned_data['text_content'],
                        settings.DEFAULT_FROM_EMAIL,
                        [addr]
                    )
                    message.attach_alternative(form.cleaned_data['html_content'], 'text/html')
                    email_messages.append(message)
                conn = mail.get_connection()
                conn.open()
                conn.send_messages(email_messages)
                conn.close()
                self.message_user(request, 'Emails sent to %d players.' % len(season_players), messages.INFO)
                return redirect('admin:tournament_season_changelist')
        else:
            form = forms.BulkEmailForm(season.seasonplayer_set.count())

        context = {
            'has_permission': True,
            'opts': self.model._meta,
            'site_url': '/',
            'original': season,
            'title': 'Bulk email',
            'form': form
        }

        return render(request, 'tournament/admin/bulk_email.html', context)
disable_inactive_users.py 文件源码 项目:django-useraudit 作者: muccg 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def handle(self, email=True, verbosity=1, **kwargs):
        self.verbosity = verbosity

        UserModel = get_user_model()
        exp = ExpirySettings.get()
        oldest = exp.earliest_possible_login

        if oldest is None:
            self._info("Account expiry not configured; nothing to do.")
            return

        self._info("Checking for users who haven't logged in since %s" % oldest)

        gone = UserModel.objects.filter(is_active=True, last_login__lt=oldest)

        for username in gone.values_list(UserModel.USERNAME_FIELD, flat=True):
            self._info("Deactiviting user: %s" % username)

        messages = list(filter(None, (self._make_email(exp, user) for user in gone)))

        count = gone.update(is_active=False)
        if count:
            self._info("%d account(s) expired" % count)

        if email and messages:
            self._info("Sending e-mails")
            connection = mail.get_connection()
            connection.send_messages(messages)

        self._info("Done")
message.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])
message.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_connection(self, fail_silently=False):
        from django.core.mail import get_connection
        if not self.connection:
            self.connection = get_connection(fail_silently=fail_silently)
        return self.connection
message.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send(self, fail_silently=False):
        """Sends the email message."""
        if not self.recipients():
            # Don't bother creating the network connection if there's nobody to
            # send to.
            return 0
        return self.get_connection(fail_silently).send_messages([self])


问题


面经


文章

微信
公众号

扫码关注公众号