当前位置: 首页>>代码示例>>Python>>正文


Python email.MessageBuilder类代码示例

本文整理汇总了Python中sentry.utils.email.MessageBuilder的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder类的具体用法?Python MessageBuilder怎么用?Python MessageBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MessageBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _send_mail

    def _send_mail(self, subject, template=None, html_template=None, body=None,
                   project=None, group=None, headers=None, context=None,
                   fail_silently=False):
        send_to = self.get_send_to(project)
        if not send_to:
            return

        subject_prefix = self.get_option('subject_prefix', project) or self.subject_prefix

        try:
            subject_prefix = subject_prefix.encode("utf-8")
            subject = subject.encode("utf-8")
        except UnicodeDecodeError:
            subject_prefix = unicode(subject_prefix, "utf-8")
            subject = unicode(subject, "utf-8")

        msg = MessageBuilder(
            subject='%s%s' % (subject_prefix, subject),
            template=template,
            html_template=html_template,
            body=body,
            headers=headers,
            context=context,
            reference=group,
        )
        msg.add_users(send_to, project=project)
        return msg.send(fail_silently=fail_silently)
开发者ID:erhuabushuo,项目名称:sentry,代码行数:27,代码来源:models.py

示例2: test_add_groupemailthread

    def test_add_groupemailthread(self, make_msgid):
        make_msgid.return_value = 'abc123'

        msg = MessageBuilder(
            subject='Test',
            body='hello world',
            html_body='<b>hello world</b>',
            reference=self.group,
        )
        msg.send(['[email protected]'])

        assert len(mail.outbox) == 1

        out = mail.outbox[0]
        assert out.to == ['[email protected]']
        assert out.subject == 'Test', 'First message should not have Re: prefix'
        assert out.extra_headers['Message-Id'] == 'abc123'
        assert 'In-Reply-To' not in out.extra_headers
        assert 'References' not in out.extra_headers
        assert out.body == 'hello world'
        assert len(out.alternatives) == 1
        assert out.alternatives[0] == (
            '<!DOCTYPE html>\n<html><body><b>hello world</b></body></html>', 'text/html',
        )

        # Our new EmailThread row was added
        assert GroupEmailThread.objects.count() == 1
        thread = GroupEmailThread.objects.all()[0]
        assert thread.msgid == 'abc123'
        assert thread.email == '[email protected]'
        assert thread.group == self.group
开发者ID:Kayle009,项目名称:sentry,代码行数:31,代码来源:tests.py

示例3: send_invite_email

    def send_invite_email(self):
        from sentry.utils.email import MessageBuilder

        context = {
            'email': self.email,
            'organization': self.organization,
            'url': absolute_uri(reverse('sentry-accept-invite', kwargs={
                'member_id': self.id,
                'token': self.token,
            })),
        }

        msg = MessageBuilder(
            subject='Join %s in using Sentry' % self.organization.name,
            template='sentry/emails/member-invite.txt',
            html_template='sentry/emails/member-invite.html',
            type='organization.invite',
            context=context,
        )

        try:
            msg.send_async([self.get_email()])
        except Exception as e:
            logger = get_logger(name='sentry.mail')
            logger.exception(e)
开发者ID:WhoTrades,项目名称:sentry,代码行数:25,代码来源:organizationmember.py

示例4: handle_project

def handle_project(plugin, project, stream):
    stream.write('# Project: %s\n' % project)
    from sentry.utils.email import MessageBuilder
    msg = MessageBuilder('test')
    msg.add_users(plugin.get_sendable_users(project), project)
    for email in msg._send_to:
        stream.write(email + '\n')
开发者ID:IthacaDream,项目名称:sentry,代码行数:7,代码来源:check_notifications.py

示例5: _build_message

    def _build_message(self, project, subject, template=None, html_template=None,
                   body=None, reference=None, reply_reference=None, headers=None,
                   context=None, send_to=None, type=None):
        if send_to is None:
            send_to = self.get_send_to(project)
        if not send_to:
            logger.debug('Skipping message rendering, no users to send to.')
            return

        subject_prefix = self.get_option('subject_prefix', project) or self._subject_prefix()
        subject_prefix = force_text(subject_prefix)
        subject = force_text(subject)

        msg = MessageBuilder(
            subject='%s%s' % (subject_prefix, subject),
            template=template,
            html_template=html_template,
            body=body,
            headers=headers,
            type=type,
            context=context,
            reference=reference,
            reply_reference=reply_reference,
        )
        msg.add_users(send_to, project=project)
        return msg
开发者ID:Cobbyzhang,项目名称:sentry,代码行数:26,代码来源:models.py

示例6: send_confirm_email_singular

    def send_confirm_email_singular(self, email, is_new_user=False):
        from sentry import options
        from sentry.utils.email import MessageBuilder

        if not email.hash_is_valid():
            email.set_hash()
            email.save()

        context = {
            'user':
            self,
            'url':
            absolute_uri(
                reverse('sentry-account-confirm-email', args=[self.id, email.validation_hash])
            ),
            'confirm_email':
            email.email,
            'is_new_user':
            is_new_user,
        }
        msg = MessageBuilder(
            subject='%sConfirm Email' % (options.get('mail.subject-prefix'), ),
            template='sentry/emails/confirm_email.txt',
            html_template='sentry/emails/confirm_email.html',
            type='user.confirm_email',
            context=context,
        )
        msg.send_async([email.email])
开发者ID:yogeshmangaj,项目名称:sentry,代码行数:28,代码来源:user.py

示例7: _send_mail

    def _send_mail(
        self,
        subject,
        template=None,
        html_template=None,
        body=None,
        project=None,
        headers=None,
        context=None,
        fail_silently=False,
    ):

        subject_prefix = self.get_option("subject_prefix", project) or self.subject_prefix

        msg = MessageBuilder(
            subject="%s%s" % (subject_prefix, subject),
            template=template,
            html_template=html_template,
            body=body,
            headers=headers,
            context=context,
        )

        send_to = self._send_to

        return msg.send(to=send_to, fail_silently=fail_silently)
开发者ID:rogerhu,项目名称:sentry-subscriptions,代码行数:26,代码来源:plugin.py

示例8: send_sso_unlink_email

    def send_sso_unlink_email(self, actor, provider):
        from sentry.utils.email import MessageBuilder
        from sentry.models import LostPasswordHash

        email = self.get_email()

        recover_uri = '{path}?{query}'.format(
            path=reverse('sentry-account-recover'),
            query=urlencode({'email': email}),
        )

        context = {
            'email': email,
            'recover_url': absolute_uri(recover_uri),
            'has_password': self.user.password,
            'organization': self.organization,
            'actor': actor,
            'provider': provider,
        }

        if not self.user.password:
            password_hash = LostPasswordHash.for_user(self.user)
            context['set_password_url'] = password_hash.get_absolute_url(mode='set_password')

        msg = MessageBuilder(
            subject='Action Required for %s' % (self.organization.name, ),
            template='sentry/emails/auth-sso-disabled.txt',
            html_template='sentry/emails/auth-sso-disabled.html',
            type='organization.auth_sso_disabled',
            context=context,
        )
        msg.send_async([email])
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:32,代码来源:organizationmember.py

示例9: build_message

def build_message(timestamp, duration, organization, user, report):
    start, stop = interval = _to_interval(timestamp, duration)

    duration_spec = durations[duration]
    message = MessageBuilder(
        subject=u'{} Report for {}: {} - {}'.format(
            duration_spec.adjective.title(),
            organization.name,
            date_format(start),
            date_format(stop),
        ),
        template='sentry/emails/reports/body.txt',
        html_template='sentry/emails/reports/body.html',
        type='report.organization',
        context={
            'duration': duration_spec,
            'interval': {
                'start': date_format(start),
                'stop': date_format(stop),
            },
            'organization': organization,
            'personal': fetch_personal_statistics(
                interval,
                organization,
                user,
            ),
            'report': to_context(report),
            'user': user,
        },
    )

    message.add_users((user.id,))

    return message
开发者ID:WhoTrades,项目名称:sentry,代码行数:34,代码来源:reports.py

示例10: _build_message

    def _build_message(self, subject, template=None, html_template=None,
                       body=None, project=None, group=None, headers=None,
                       context=None):
        """
        Identical function to _build_message for sentry_mail, by the Sentry
        Team, except for the send_to list that is received is assigned to
        the message's list instead of appended. 
        """

        send_to = self.get_option('emails', project) or []
        if not send_to:
            logger.debug('Skipping message rendering, no users to send to.')
            return

        subject_prefix = self.get_option('subject_prefix', project) or \
                self.subject_prefix
        subject_prefix = force_text(subject_prefix)
        subject = force_text(subject)

        msg = MessageBuilder(
            subject='%s%s' % (subject_prefix, subject),
            template=template,
            html_template=html_template,
            body=body,
            headers=headers,
            context=context,
            reference=group,
        )
        msg._send_to = set(send_to)

        return msg
开发者ID:clearpathrobotics,项目名称:sentry-custom-mailer,代码行数:31,代码来源:plugin.py

示例11: send_approved_email

    def send_approved_email(self):
        from sentry.utils.email import MessageBuilder

        user = self.member.user
        email = user.email
        organization = self.team.organization

        context = {
            'email': email,
            'name': user.get_display_name(),
            'organization': organization,
            'team': self.team,
        }

        msg = MessageBuilder(
            subject='Sentry Access Request',
            template='sentry/emails/access-approved.txt',
            html_template='sentry/emails/access-approved.html',
            context=context,
        )

        try:
            msg.send([email])
        except Exception as e:
            logger = logging.getLogger('sentry.mail.errors')
            logger.exception(e)
开发者ID:ChadKillingsworth,项目名称:sentry,代码行数:26,代码来源:organizationaccessrequest.py

示例12: send_request_email

    def send_request_email(self):
        from sentry.utils.email import MessageBuilder

        user = self.member.user
        email = user.email
        organization = self.team.organization

        context = {
            'email': email,
            'name': user.get_display_name(),
            'organization': organization,
            'team': self.team,
            'url': absolute_uri(reverse('sentry-organization-members', kwargs={
                'organization_slug': organization.slug,
            }) + '?ref=access-requests'),
        }

        msg = MessageBuilder(
            subject='Sentry Access Request',
            template='sentry/emails/request-team-access.txt',
            html_template='sentry/emails/request-team-access.html',
            context=context,
        )

        try:
            msg.send([email])
        except Exception as e:
            logger = logging.getLogger('sentry.mail.errors')
            logger.exception(e)
开发者ID:ChadKillingsworth,项目名称:sentry,代码行数:29,代码来源:organizationaccessrequest.py

示例13: test_with_users

    def test_with_users(self):
        project = self.project

        user_a = User.objects.create(email='[email protected]')
        user_b = User.objects.create(email='[email protected]')
        user_c = User.objects.create(email='[email protected]')

        UserOption.objects.create(
            user=user_b,
            key='alert_email',
            value='[email protected]',
        )
        UserOption.objects.create(
            user=user_c,
            project=project,
            key='mail:email',
            value='[email protected]',
        )

        msg = MessageBuilder(
            subject='Test',
            body='hello world',
            html_body='<!DOCTYPE html>\n<b>hello world</b>',
        )
        msg.add_users([user_a.id, user_b.id, user_c.id], project=project)
        msg.send()

        assert len(mail.outbox) == 3

        assert sorted([out.to[0] for out in mail.outbox]) == [
            '[email protected]',
            '[email protected]',
            '[email protected]',
        ]
开发者ID:Kayle009,项目名称:sentry,代码行数:34,代码来源:tests.py

示例14: test_fake_dont_send

    def test_fake_dont_send(self):
        project = self.project

        user_a = User.objects.create(email=create_fake_email('foo', 'fake'))
        user_b = User.objects.create(email=create_fake_email('bar', 'fake'))
        user_c = User.objects.create(email=create_fake_email('baz', 'fake'))

        UserOption.objects.create(
            user=user_b,
            key='alert_email',
            value=create_fake_email('fizzle', 'fake'),
        )
        UserOption.objects.create(
            user=user_c,
            project=project,
            key='mail:email',
            value=create_fake_email('bazzer', 'fake'),
        )

        msg = MessageBuilder(
            subject='Test',
            body='hello world',
            html_body='<!DOCTYPE html>\n<b>hello world</b>',
        )
        msg.add_users([user_a.id, user_b.id, user_c.id], project=project)
        msg.send()

        assert len(mail.outbox) == 0
开发者ID:Kayle009,项目名称:sentry,代码行数:28,代码来源:tests.py

示例15: test_reply_reference

    def test_reply_reference(self, make_msgid):
        make_msgid.return_value = 'abc123'

        msg = MessageBuilder(
            subject='Test',
            body='hello world',
            html_body='<b>hello world</b>',
            reference=self.activity,
            reply_reference=self.group,
        )
        msg.send(['[email protected]'])

        assert len(mail.outbox) == 1

        out = mail.outbox[0]
        assert out.to == ['[email protected]']
        assert out.subject == 'Re: Test'
        assert out.extra_headers['Message-Id'] == 'abc123'
        assert 'In-Reply-To' not in out.extra_headers
        assert 'References' not in out.extra_headers
        assert out.body == 'hello world'
        assert len(out.alternatives) == 1
        assert out.alternatives[0] == (
            '<!DOCTYPE html>\n<html><body><b>hello world</b></body></html>',
            'text/html',
        )

        # Our new EmailThread row was added
        assert GroupEmailThread.objects.count() == 1
        thread = GroupEmailThread.objects.all()[0]
        assert thread.msgid == 'abc123'
        assert thread.email == '[email protected]'
        assert thread.group == self.group

        # new msgid for the next message
        make_msgid.return_value = '321cba'
        msg.send(['[email protected]'])

        assert len(mail.outbox) == 2

        out = mail.outbox[1]
        assert out.to == ['[email protected]']
        assert out.subject == 'Re: Test'
        assert out.extra_headers['Message-Id'] == '321cba'
        assert out.extra_headers['In-Reply-To'] == 'abc123'
        assert out.extra_headers['References'] == 'abc123'
        assert out.body == 'hello world'
        assert len(out.alternatives) == 1
        assert out.alternatives[0] == (
            '<!DOCTYPE html>\n<html><body><b>hello world</b></body></html>',
            'text/html',
        )

        # Our new GroupEmailThread row was added
        assert GroupEmailThread.objects.count() == 1, 'Should not have added a new row'
        assert GroupEmailThread.objects.all()[0].msgid == 'abc123', 'msgid should not have changed'
开发者ID:duanshuaimin,项目名称:sentry,代码行数:56,代码来源:tests.py


注:本文中的sentry.utils.email.MessageBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。