當前位置: 首頁>>代碼示例>>Python>>正文


Python Mail.set_text方法代碼示例

本文整理匯總了Python中sendgrid.Mail.set_text方法的典型用法代碼示例。如果您正苦於以下問題:Python Mail.set_text方法的具體用法?Python Mail.set_text怎麽用?Python Mail.set_text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sendgrid.Mail的用法示例。


在下文中一共展示了Mail.set_text方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_send

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def test_send(self):
     m = Mail()
     m.add_to('John, Doe <[email protected]>')
     m.set_subject('test')
     m.set_html('WIN')
     m.set_text('WIN')
     m.set_from('[email protected]')
     m.set_asm_group_id(42)
     m.add_cc('[email protected]')
     m.add_bcc('[email protected]')
     m.add_substitution('subKey', 'subValue')
     m.add_section('testSection', 'sectionValue')
     m.add_category('testCategory')
     m.add_unique_arg('testUnique', 'uniqueValue')
     m.add_filter('testFilter', 'filter', 'filterValue')
     m.add_attachment_stream('testFile', 'fileValue')
     url = self.sg._build_body(m)
     url.pop('api_key', None)
     url.pop('api_user', None)
     url.pop('date', None)
     test_url = json.loads('''
         {
             "to[]": ["[email protected]"],
             "toname[]": ["John Doe"],
             "html": "WIN",
             "text": "WIN",
             "subject": "test",
             "files[testFile]": "fileValue",
             "from": "[email protected]",
             "cc[]": ["[email protected]"],
             "bcc[]": ["[email protected]"]
         }
         ''')
     test_url['x-smtpapi'] = json.dumps(json.loads('''
         {
             "sub": {
                 "subKey": ["subValue"]
             },
             "section": {
                 "testSection":"sectionValue"
             },
             "category": ["testCategory"],
             "unique_args": {
                 "testUnique":"uniqueValue"
             },
             "filters": {
                 "testFilter": {
                     "settings": {
                         "filter": "filterValue"
                     }
                 }
             },
             "asm_group_id": 42
         }
         '''))
     
     try:
         self.assertItemsEqual(url, test_url)
     except: # Python 3+
         self.assertCountEqual(url, test_url)
開發者ID:Adomako-Bismark,項目名稱:sendgrid-python,代碼行數:62,代碼來源:test_mail_v2.py

示例2: test_send

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def test_send(self):
   m = Mail()
   m.add_to('John, Doe <[email protected]>')
   m.set_subject('test')
   m.set_html('WIN')
   m.set_text('WIN')
   m.set_from('[email protected]')
   m.add_substitution('subKey', 'subValue')
   m.add_section('testSection', 'sectionValue')
   m.add_category('testCategory')
   m.add_unique_arg('testUnique', 'uniqueValue')
   m.add_filter('testFilter', 'filter', 'filterValue')
   m.add_attachment_stream('testFile', 'fileValue')
   self.sg.send(m)
   url = self.sg._build_body(m)
   url.pop('api_key', None)
   url.pop('api_user', None)
   url.pop('date', None)
   testUrl = json.loads('''{"to[]": ["[email protected]"],
   "toname[]": ["John Doe"],
   "html": "WIN",
   "text": "WIN",
   "subject": "test",
   "files[testFile]": "fileValue",
   "from": "[email protected]",
   "headers": "",
   "fromname": "",
   "replyto": ""}''')
   testUrl['x-smtpapi'] = json.dumps(json.loads('''{"sub":{"subKey":["subValue"]},
     "section":{"testSection":"sectionValue"},
     "category":["testCategory"],
     "unique_args":{"testUnique":"uniqueValue"},
     "filters":{"testFilter":{"settings":{"filter":"filterValue"}}}}'''))
   self.assertEqual(url, testUrl)
開發者ID:miphreal,項目名稱:sendgrid-python,代碼行數:36,代碼來源:__init__.py

示例3: send_activation_mail

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def send_activation_mail(self):
     message = Mail()
     message.add_to(self.info['email'])
     message.set_subject('UthPortal activation')
     address = self.info['email']
     token = self.info['token']
     auth_id = self.info['auth_id']
     self.logger.debug('domain: ' + self._domain)
     #TODO: make some proper html
     message.set_html(
         "Please click on the following link to activate your account:\
         <a href={0}/api/v1/users/activate?email={1}&token={2}>Activate</a>, \
         This is your 8-digit unique user id: {3}\
         Use this in your app, when asked for it.\
         This id is used to personalize your push notifications.\
         Please don't share this ID as it is supposed to be kept secret."\
         .format(self._domain, address, token, auth_id))
     message.set_text('Token: {0}, 8-digit: {1}'.format(token, auth_id))
     message.set_from('UthPortal <%s>' % self._email_from)
     try:
         self._sg.send(message)
     except SendGridError as error:
         self.logger.error('SendGrid error: ' + str(error))
         raise NetworkError("Cannot send activation-email.", 500)
     except SendGridClientError as error:
         self.logger.error('SendGrid CLIENT error: ' + error.args[1])
         raise NetworkError('Cannot send activation e-mail.', 500)
     except SendGridServerError as error:
         self.logger.error('SendGrid SERVER error: [{0}] -> [{1}] ',format(
             error.args[0],
             error.args[1]
         ))
         raise NetworkError('Mail server currently un-available', 503)
開發者ID:GeorgeTG,項目名稱:uthportal-server,代碼行數:35,代碼來源:users.py

示例4: test_emails

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
def test_emails():
    test_emails = ['[email protected]']

    all_shows = shows_this_week()
    text = all_shows_to_markdown(all_shows)
    html = markdown(text)

    today, next_week = week_interval()
    tomorrow = today + relativedelta(days=+1)
    date_format = "%m/%d"

    responses = []

    # make a secure connection to SendGrid
    sg = SendGridClient(SENDGRID_USER, SENDGRID_PASSWORD, secure=True)

    for email in test_emails:
        # make a message object
        message = Mail()
        message.set_subject('NYC Jazz Digest: {} to {}'.format(tomorrow.strftime(date_format), next_week.strftime(date_format)))
        message.set_html(html)
        message.set_text(text)
        message.set_from('NYC Jazz Digest <[email protected]>')

        # add a recipient
        message.add_to(email)

        # use the Web API to send your message
        responses.append(str(sg.send(message)))

    return '\n'.join(responses)
開發者ID:adamreis,項目名稱:nyc-jazz,代碼行數:33,代碼來源:email_stuff.py

示例5: send_digest

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
def send_digest():
    sg = SendGridClient(SENDGRID_USER, SENDGRID_PASSWORD, secure=True)
    responses = []

    today, next_week = week_interval()
    tomorrow = today + relativedelta(days=+1)
    date_format = "%m/%d"
    subject = 'NYC Jazz Digest: {} to {}'.format(tomorrow.strftime(date_format), next_week.strftime(date_format))
    from_addr = 'NYC Jazz Digest <[email protected]>'

    all_shows = shows_this_week()
    text = all_shows_to_markdown(all_shows)
    
    for user in User.query(User.opt_out == False).fetch():
        unsubcribe_link = ROOT_URL + '/unsubscribe/' + user.uuid
        unsubscribe_phrase = "\n\nClick [here]({}) to unsubscribe.".format(unsubcribe_link)
        text += unsubscribe_phrase
        html = markdown(text)

        message = Mail()
        message.set_subject(subject)
        message.set_html(html)
        message.set_text(text)
        message.set_from(from_addr)

        # add a recipient
        message.add_to(user.email)

        # use the Web API to send your message
        responses.append(str(sg.send(message)))

    return '\n'.join(responses)
開發者ID:adamreis,項目名稱:nyc-jazz,代碼行數:34,代碼來源:email_stuff.py

示例6: index

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def index(self):
     if request.method=='GET':
         user_emails = db_session.query(User).filter(User.new_features_subscription == True)
         email_list = []
         for user in user_emails:
             email_list.append(user.email)
             email_list.append(';')
         context = {'user_emails': email_list}
         return self.render('sendemail.html', **context)
     else:
         jsondata = request.get_json(force=True)
         users_send_email_to = db_session.query(User).filter(User.new_features_subscription == True)
         message = Mail()
         message.set_subject(jsondata['subject'].encode("utf8"))
         message.set_text(jsondata['message'].encode("utf8"))
         message.set_from('ANYWAY Team <[email protected]>')
         for user in users_send_email_to:
             message.add_bcc(user.email)
         try:
             status, msg = sg.send(message)
         except SendGridClientError:
             return "Error occurred while trying to send the emails"
         except SendGridServerError:
             return "Error occurred while trying to send the emails"
         return "Email/s Sent"
開發者ID:agamaloni,項目名稱:anyway,代碼行數:27,代碼來源:main.py

示例7: test_send

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def test_send(self):
     m = Mail()
     m.add_to("John, Doe <[email protected]>")
     m.set_subject("test")
     m.set_html("WIN")
     m.set_text("WIN")
     m.set_from("[email protected]")
     m.add_substitution("subKey", "subValue")
     m.add_section("testSection", "sectionValue")
     m.add_category("testCategory")
     m.add_unique_arg("testUnique", "uniqueValue")
     m.add_filter("testFilter", "filter", "filterValue")
     m.add_attachment_stream("testFile", "fileValue")
     url = self.sg._build_body(m)
     url.pop("api_key", None)
     url.pop("api_user", None)
     url.pop("date", None)
     test_url = json.loads(
         """
         {
             "to[]": ["[email protected]"],
             "toname[]": ["John Doe"],
             "html": "WIN",
             "text": "WIN",
             "subject": "test",
             "files[testFile]": "fileValue",
             "from": "[email protected]"
         }
         """
     )
     test_url["x-smtpapi"] = json.dumps(
         json.loads(
             """
         {
             "to" : ["John, Doe <[email protected]>"],
             "sub": {
                 "subKey": ["subValue"]
             },
             "section": {
                 "testSection":"sectionValue"
             },
             "category": ["testCategory"],
             "unique_args": {
                 "testUnique":"uniqueValue"
             },
             "filters": {
                 "testFilter": {
                     "settings": {
                         "filter": "filterValue"
                     }
                 }
             }
         }
         """
         )
     )
     self.assertEqual(url, test_url)
開發者ID:RekindleInc,項目名稱:sendgrid-python,代碼行數:59,代碼來源:__init__.py

示例8: sendEmail

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
def sendEmail(sender, recipient, subject, html, text) :
    sg= SendGridClient('ecpf', 'Iheart1!', secure=True)
    message = Mail()
    message.set_subject(subject)
    message.set_html(html)
    message.set_text(text)
    message.set_from(sender)
    message.add_to(recipient)
    sg.send(message)
    return True
開發者ID:Greenfeldandsmithventures,項目名稱:nOCD-GP,代碼行數:12,代碼來源:auxillaryFunctions.py

示例9: test_drop_to_header

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
    def test_drop_to_header(self):
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_from('[email protected]')
        m.set_subject('test')
        m.set_text('test')
        m.add_bcc('John, Doe <[email protected]>')
        url =  self.sg._build_body(m)

        print url
開發者ID:yred,項目名稱:sendgrid-python,代碼行數:12,代碼來源:__init__.py

示例10: test_drop_to_header

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def test_drop_to_header(self):
     smtpapi = "{}"
     m = Mail()
     m.add_to("John, Doe <[email protected]>")
     m.set_from("[email protected]")
     m.set_subject("test")
     m.set_text("test")
     m.add_bcc("John, Doe <[email protected]>")
     url = self.sg._build_body(m)
     self.assertEqual(smtpapi, url["x-smtpapi"])
開發者ID:RekindleInc,項目名稱:sendgrid-python,代碼行數:12,代碼來源:__init__.py

示例11: config_mail

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
def config_mail():
    message = Mail()
    message.add_to("<[email protected]>")
    message.add_to_name("Kumar, Palani")
    message.set_from("kavinp[email protected]")
    message.set_from_name("Kavin");
    message.set_subject("Test message.,")
    message.set_text("Test text")
    message.set_html("<i><b>Test HTML</b></i>")
    message.set_replyto("[email protected]")
    message.set_date(rfc822.formatdate())
    return message
開發者ID:kapalani,項目名稱:test-sendgrid-api,代碼行數:14,代碼來源:test.py

示例12: send_email

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
    def send_email(self, request):
        # make a secure connection to SendGrid
        sg = SendGridClient(get_mail_username(), get_mail_pass(), secure=True)

        # make a message object
        message = Mail()
        message.set_subject('message subject')
        message.set_html('<strong>HTML message body</strong>')
        message.set_text('plaintext message body')
        message.set_from('[email protected]')

        # add a recipient
        message.add_to('John Doe <[email protected]>')

        # use the Web API to send your message
        sg.send(message)
        return message_types.VoidMessage()
開發者ID:Yury191,項目名稱:hyperAdmit,代碼行數:19,代碼來源:endpoint_classes.py

示例13: get

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
    def get(self):
        # make a secure connection to SendGrid
        #sg = SendGridClient('userid', 'password', secure=True)
        print sg

        # make a message object
        message = Mail()
        message.set_subject('message subject')
        message.set_html('<strong>HTML message body</strong>')
        message.set_text('plaintext message body')
        message.set_from('[email protected]')

        # add a recipient
        message.add_to('Name <email>')

        # use the Web API to send your message
        sg.send(message)
        self.response.write('email sent.')
開發者ID:Jasminezhou,項目名稱:angular-helioroofing,代碼行數:20,代碼來源:main.py

示例14: test__build_body_unicode

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
 def test__build_body_unicode(self):
     """test _build_body() handles encoded unicode outside ascii range"""
     from_email = '\xd0\x9d\xd0\xb8\xd0\xba\xd0\[email protected]'
     from_name = '\xd0\x9a\xd0\xbb\xd0\xb0\xd0\xb2\xd0\xb4\xd0\xb8\xd1\x8f'
     subject = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
     text = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
     html = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
     m = Mail()
     m.add_to('John, Doe <[email protected]>')
     m.set_subject(subject)
     m.set_html(html)
     m.set_text(text)
     m.set_from("%s <%s>" % (from_name, from_email))
     url = self.sg._build_body(m)
     self.assertEqual(from_email, url['from'])
     self.assertEqual(from_name, url['fromname'])
     self.assertEqual(subject, url['subject'])
     self.assertEqual(text, url['text'])
     self.assertEqual(html, url['html'])
開發者ID:Adomako-Bismark,項目名稱:sendgrid-python,代碼行數:21,代碼來源:test_mail_v2.py

示例15: send_mail

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_text [as 別名]
def send_mail():
    """
    Send email with sendgrid sdk
    """
    to_email = request.form.get('to')
    subject = request.form.get('subject')
    body = request.form.get('body')
    text_body = request.form.get('text_body')
    from_email = request.form.get('from')

    utf8_body = body.encode('utf-8')
    utf8_text_body = text_body.encode('utf-8')

    message = Mail()
    message.set_subject(subject)
    message.set_html(utf8_body)
    message.set_text(utf8_text_body)
    message.set_from(from_email)
    message.add_to(to_email)
    sg.send(message)
    logger.info("Email is sent to %s" % to_email)
    return ('', 204)
開發者ID:olala7846,項目名稱:ntuvb-allstar,代碼行數:24,代碼來源:voting.py


注:本文中的sendgrid.Mail.set_text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。