• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python message.Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_attach

    def test_attach(self):

        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        msg = Message(
            subject="testing",
            recipients=["[email protected]"],
            sender='sender',
            body="testing"
            )

        attachment = Attachment(
            data=b"this is a test",
            content_type="text/plain"
            )

        msg.attach(attachment)

        a = msg.attachments[0]

        self.assertTrue(a.filename is None)
        self.assertEqual(a.disposition, 'attachment')
        self.assertEqual(a.content_type, "text/plain")
        self.assertEqual(a.data, b"this is a test")
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:25,代码来源:test_message.py


示例2: mailer_send

def mailer_send(subject="!",
                sender=None,
                recipients=[],
                body=None,
                html=None,
                attachments=[]):
    try:
        request = get_current_request()
        if sender is None:
            sender = request.registry.settings['mail.default_sender']

        mailer = get_mailer(request)
        message = Message(subject=subject,
                          sender=sender,
                          recipients=recipients,
                          body=body,
                          html=html)
        for attachment in attachments:
            attachment = Attachment(attachment.title,
                                    attachment.mimetype,
                                    attachment)
            message.attach(attachment)

        if transaction.get().status == Status.COMMITTED:
            mailer.send_immediately(message)
        else:
            mailer.send(message)

    except Exception:
        pass
开发者ID:ecreall,项目名称:nova-ideo,代码行数:30,代码来源:__init__.py


示例3: confirmation

def confirmation(request):
    '''
    Generates confirmation page and confirmation emails to user and D2L site 
    admin.
    '''
    if not logged_in(request):
        return HTTPFound(location=request.route_url('login'))
    form = SelectCoursesForm()
    csrf_token = request.session.get_csrf_token()

    submitter_email = request.session['uniqueName'] + '@' + \
        request.registry.settings['EMAIL_DOMAIN']
    name = request.session['firstName'] + ' ' + request.session['lastName']
    sender = request.registry.settings['mail.username']

    '''remove for production'''
    submitter_email = '[email protected]'

    message = Message(subject="Course Combine Confirmation",
        sender=sender,
        recipients=[sender, submitter_email])
    message.body = make_msg_text(name, submitter_email, request)
    message.html = make_msg_html(name, submitter_email, request)
    mailer = get_mailer(request)
    mailer.send_immediately(message, fail_silently=False)

    return{'csrf_token': csrf_token,
        'name': name,
        'form': form, 
        'base_course': request.session['base_course'],
        'courses_to_combine': request.session['courses_to_combine']
        }
开发者ID:lookerb,项目名称:course-combine,代码行数:32,代码来源:views.py


示例4: test_is_bad_headers_if_bad_headers

    def test_is_bad_headers_if_bad_headers(self):

        from pyramid_mailer.message import Message

        msg = Message(subject="testing\n\r", sender="[email protected]\nexample.com", body="testing", recipients=["[email protected]"])

        self.assertTrue(msg.is_bad_headers())
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:7,代码来源:test_message.py


示例5: test_to_message_multipart_with_qpencoding

 def test_to_message_multipart_with_qpencoding(self):
     from pyramid_mailer.message import Message, Attachment
     response = Message(
         recipients=['To'],
         sender='From',
         subject='Subject',
         body='Body',
         html='Html'
         )
     this = os.path.abspath(__file__)
     with open(this, 'rb') as data:
         attachment = Attachment(
             filename=this,
             content_type='application/octet-stream',
             disposition='disposition',
             transfer_encoding='quoted-printable',
             data=data,
             )
         response.attach(attachment)
         message = response.to_message()
         payload = message.get_payload()[1]
     self.assertEqual(
         payload.get('Content-Transfer-Encoding'),
         'quoted-printable'
         )
     self.assertEqual(
         payload.get_payload(),
         _qencode(self._read_filedata(this,'rb')).decode('ascii')
         )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:29,代码来源:test_message.py


示例6: test_is_bad_headers_if_subject_empty

    def test_is_bad_headers_if_subject_empty(self):
        from pyramid_mailer.message import Message
        msg = Message(sender="[email protected]",
                      body="testing",
                      recipients=["[email protected]"])

        self.assert_(not(msg.is_bad_headers()))
开发者ID:AnneGilles,项目名称:pyramid_mailer,代码行数:7,代码来源:tests.py


示例7: test_attach_as_body

    def test_attach_as_body(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        text = text_encoded.decode(charset)
        transfer_encoding = 'quoted-printable'
        body = Attachment(
            data=text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="[email protected]",
            recipients=["[email protected]"],
            body=body
            )
        body_part = msg.to_message()

        self.assertEqual(
            body_part['Content-Type'],
            'text/plain; charset="iso-8859-1"'
            )
        self.assertEqual(
            body_part['Content-Transfer-Encoding'],
            transfer_encoding
            )
        self.assertEqual(
            body_part.get_payload(),
            _qencode(text_encoded).decode('ascii')
            )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:32,代码来源:test_message.py


示例8: test_attach_as_html

    def test_attach_as_html(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        html_encoded = b'<p>' + text_encoded + b'</p>'
        html_text = html_encoded.decode(charset)
        transfer_encoding = 'quoted-printable'
        html = Attachment(
            data=html_text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="[email protected]",
            recipients=["[email protected]"],
            html=html,
            )

        html_part = msg.to_message()

        self.assertEqual(
            html_part['Content-Type'],
            'text/html; charset="iso-8859-1"'
            )
        self.assertEqual(
            html_part['Content-Transfer-Encoding'],
            transfer_encoding
            )
        self.assertEqual(
            html_part.get_payload(),
            _qencode(html_encoded).decode('ascii')
            )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:34,代码来源:test_message.py


示例9: test_attach_as_body_and_html_utf8

    def test_attach_as_body_and_html_utf8(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = "utf-8"
        # greek small letter iota with dialtyika and tonos; this character
        # cannot be encoded to either ascii or latin-1, so utf-8 is chosen
        text_encoded = b"\xce\x90"
        text = text_encoded.decode(charset)
        html_encoded = b"<p>" + text_encoded + b"</p>"
        html_text = html_encoded.decode(charset)
        transfer_encoding = "quoted-printable"
        body = Attachment(data=text, transfer_encoding=transfer_encoding)
        html = Attachment(data=html_text, transfer_encoding=transfer_encoding)
        msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body=body, html=html)
        message = msg.to_message()
        body_part, html_part = message.get_payload()

        self.assertEqual(body_part["Content-Type"], 'text/plain; charset="utf-8"')

        self.assertEqual(body_part["Content-Transfer-Encoding"], transfer_encoding)

        payload = body_part.get_payload()
        self.assertEqual(payload, _qencode(text_encoded).decode("ascii"))

        self.assertEqual(html_part["Content-Type"], 'text/html; charset="utf-8"')
        self.assertEqual(html_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = html_part.get_payload()
        self.assertEqual(payload, _qencode(html_encoded).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:29,代码来源:test_message.py


示例10: test_attach_as_html

    def test_attach_as_html(self):
        import codecs
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'latin-1'
        text_encoded = b('LaPe\xf1a')
        text = text_encoded.decode(charset)
        text_html = '<p>' + text + '</p>'
        transfer_encoding = 'quoted-printable'
        html = Attachment(data=text_html,
                          transfer_encoding=transfer_encoding)
        msg = Message(subject="testing",
                      sender="[email protected]",
                      recipients=["[email protected]"],
                      html=html)
        html_part = msg.to_message()

        self.assertEqual(
            html_part['Content-Type'], 'text/html')
        self.assertEqual(
            html_part['Content-Transfer-Encoding'], transfer_encoding)
        self.assertEqual(html_part.get_payload(),
                         codecs.getencoder('quopri_codec')(
                             text_html.encode(charset))[0].decode('ascii'))
开发者ID:ccomb,项目名称:pyramid_mailer,代码行数:25,代码来源:tests.py


示例11: email

    def email(self):
        id = self.request.matchdict['id']
        test = Tests.by({'id':id,'alias':self.request.user.alias}).first()
        if not test:
            raise HTTPForbidden()
        file = self._generate_pdf(id)
        self.response['id'] = id
        self.response['emails'] = self.request.params.get('email.addresses',None)
        
        if 'form.submitted' in self.request.params:
            if self.request.params['email.ok'] == '1':
                emails = self.request.params['email.addresses'].replace(' ','').split(',')
                for email in emails:
                    if not Validate.email(email):
                        self.notify('Invalid email address',warn=True)
                        return self.template('email.pt')
                        
                try:
                    message = Message(subject=self._email_fmt(id, str(Properties.get('MAILER_TO_SUBJECT','Submission'))),
                                      sender=str(Properties.get('MAILER_GLOBAL_FROM_ADDRESS','System')),
                                      recipients=emails,
                                      body=self._email_fmt(id, str(Properties.get('MAILER_BODY','Submission'))))
                    attachment = Attachment('submission_' + str(id) + '.pdf', 'application/pdf', file)
                    message.attach(attachment)
                    mailer = get_mailer(self.request)
                    mailer.send(message)
                    self.notify('Email sent!')
                except Exception as e:
                    print "ERROR: " + str(e)
                    self.notify('Unable to send email!',warn=True)
            else:
                self.notify('Unable to send example email!',warn=True)

        return self.template('email.pt')
开发者ID:polklibrary,项目名称:quizsmith,代码行数:34,代码来源:score.py


示例12: test_attach_as_body_and_html_latin1

    def test_attach_as_body_and_html_latin1(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = "iso-8859-1"
        text_encoded = b"LaPe\xf1a"
        text = text_encoded.decode(charset)
        html_encoded = b"<p>" + text_encoded + b"</p>"
        html_text = html_encoded.decode(charset)
        transfer_encoding = "quoted-printable"
        body = Attachment(data=text, transfer_encoding=transfer_encoding)
        html = Attachment(data=html_text, transfer_encoding=transfer_encoding)
        msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body=body, html=html)
        message = msg.to_message()
        body_part, html_part = message.get_payload()

        self.assertEqual(body_part["Content-Type"], 'text/plain; charset="iso-8859-1"')
        self.assertEqual(body_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = body_part.get_payload()
        self.assertEqual(payload, _qencode(text_encoded).decode("ascii"))

        self.assertEqual(html_part["Content-Type"], 'text/html; charset="iso-8859-1"')
        self.assertEqual(html_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = html_part.get_payload()
        self.assertEqual(payload, _qencode(html_encoded).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:25,代码来源:test_message.py


示例13: accountant_mail

def accountant_mail(appstruct):
    """
    this function returns a message object for the mailer

    it consists of a mail body and an attachment attached to it
    """
    unencrypted = make_mail_body(appstruct)
    #print("accountant_mail: mail body: \n%s") % unencrypted
    #print("accountant_mail: type of mail body: %s") % type(unencrypted)
    encrypted = encrypt_with_gnupg(unencrypted)
    #print("accountant_mail: mail body (enc'd): \n%s") % encrypted
    #print("accountant_mail: type of mail body (enc'd): %s") % type(encrypted)

    message = Message(
        subject="[C3S] Yes! a new member",
        sender="[email protected]",
        recipients=["[email protected]"],
        body=encrypted
    )
    #print("accountant_mail: csv_payload: \n%s") % generate_csv(appstruct)
    #print(
    #    "accountant_mail: type of csv_payload: \n%s"
    #) % type(generate_csv(appstruct))
    csv_payload_encd = encrypt_with_gnupg(generate_csv(appstruct))
    #print("accountant_mail: csv_payload_encd: \n%s") % csv_payload_encd
    #print(
    #    "accountant_mail: type of csv_payload_encd: \n%s"
    #) % type(csv_payload_encd)

    attachment = Attachment(
        "C3S-SCE-AFM.csv.gpg", "application/gpg-encryption",
        csv_payload_encd)
    message.attach(attachment)

    return message
开发者ID:plamut,项目名称:c3sMembership,代码行数:35,代码来源:utils.py


示例14: test_cc_without_recipients_2

    def test_cc_without_recipients_2(self):

        from pyramid_mailer.message import Message

        msg = Message(subject="testing", sender="[email protected]", body="testing", cc=["[email protected]"])
        response = msg.to_message()
        self.assertTrue("Cc: [email protected]" in text_type(response))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:7,代码来源:test_message.py


示例15: confirmation

def confirmation(request):
    """
    Generates confirmation page and confirmation emails to user and D2L site 
    admin.
    """
    if not logged_in(request):
        return HTTPFound(location=request.route_url("login"))
    form = SelectCoursesForm()
    csrf_token = request.session.get_csrf_token()

    submitter_email = request.session["uniqueName"] + "@" + request.registry.settings["EMAIL_DOMAIN"]
    name = request.session["firstName"] + " " + request.session["lastName"]
    sender = request.registry.settings["mail.username"]

    """remove for production"""
    submitter_email = "[email protected]"

    message = Message(subject="Course Combine Confirmation", sender=sender, recipients=[sender, submitter_email])
    message.body = make_msg_text(name, submitter_email, request)
    message.html = make_msg_html(name, submitter_email, request)
    mailer = get_mailer(request)
    mailer.send_immediately(message, fail_silently=False)

    return {
        "csrf_token": csrf_token,
        "name": name,
        "form": form,
        "base_course": request.session["base_course"],
        "courses_to_combine": request.session["courses_to_combine"],
    }
开发者ID:antholo,项目名称:d2lapps,代码行数:30,代码来源:views.py


示例16: test_add_cc

    def test_add_cc(self):

        from pyramid_mailer.message import Message

        msg = Message("testing")
        msg.add_cc("[email protected]")

        self.assertEqual(msg.cc, ["[email protected]"])
开发者ID:fschulze,项目名称:pyramid_mailer,代码行数:8,代码来源:tests.py


示例17: test_add_recipient

    def test_add_recipient(self):

        from pyramid_mailer.message import Message

        msg = Message("testing")
        msg.add_recipient("[email protected]")

        self.assert_(msg.recipients == ["[email protected]"])
开发者ID:AnneGilles,项目名称:pyramid_mailer,代码行数:8,代码来源:tests.py


示例18: test_add_bcc

    def test_add_bcc(self):

        from pyramid_mailer.message import Message

        msg = Message("testing")
        msg.add_bcc("[email protected]")

        self.assert_(msg.bcc == ["[email protected]"])
开发者ID:AnneGilles,项目名称:pyramid_mailer,代码行数:8,代码来源:tests.py


示例19: _send_annotation

 def _send_annotation(self, body, subject, recipients):
     body = body.decode('utf8')
     subject = subject.decode('utf8')
     message = Message(subject=subject,
                       recipients=recipients,
                       body=body)
     self.mailer.send(message)
     log.info('sent: %s', message.to_message().as_string())
开发者ID:ercchy,项目名称:h,代码行数:8,代码来源:notifier.py


示例20: test_to_message_with_html_attachment

    def test_to_message_with_html_attachment(self):
        from pyramid_mailer.message import Message, Attachment

        response = Message(recipients=["To"], sender="From", subject="Subject", body="Body")
        attachment = Attachment(data=b"data", content_type="text/html")
        response.attach(attachment)
        message = response.to_message()
        att_payload = message.get_payload()[1]
        self.assertEqual(att_payload["Content-Type"], 'text/html; charset="us-ascii"')
        self.assertEqual(att_payload.get_payload(), _bencode(b"data").decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:10,代码来源:test_message.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyramid_simpleform.Form类代码示例发布时间:2022-05-27
下一篇:
Python mailer.Mailer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap