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


Python sendgrid.SendGridAPIClient方法代碼示例

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


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

示例1: send_email

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send_email():
    recipient = request.form.get('to')
    if not recipient:
        return ('Please provide an email address in the "to" query string '
                'parameter.'), 400

    message = Mail(
        from_email=SENDGRID_SENDER,
        to_emails='{},'.format(recipient),
        subject='This is a test email',
        html_content='<strong>Example</strong> message.')
    sg = sendgrid.SendGridAPIClient(SENDGRID_API_KEY)

    response = sg.send(message)

    if response.status_code != 202:
        return 'An error occurred: {}'.format(response.body), 500

    return 'Email sent.'
# [END gae_flex_sendgrid] 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:22,代碼來源:main.py

示例2: __init__

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def __init__(self, app):
        """Check config settings and setup SendGrid Web API v3.

        Args:
            app(Flask): The Flask application instance.
        """

        super(SendgridEmailAdapter, self).__init__(app)

        sendgrid_api_key = app.config.get('SENDGRID_API_KEY')
        if not sendgrid_api_key:
            raise ConfigError(
                "The SENDGRID_API_KEY setting is missing. Set SENDGRID_API_KEY in your app config.")

        # Setup sendgrid-python
        try:
            from sendgrid import SendGridAPIClient
            self.sg = SendGridAPIClient(apikey=sendgrid_api_key)
        except ImportError:
            raise ConfigError(SENDGRID_IMPORT_ERROR_MESSAGE) 
開發者ID:lingthio,項目名稱:Flask-User,代碼行數:22,代碼來源:sendgrid_email_adapter.py

示例3: __init__

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def __init__(self, sender, recipient, auth, custom=None):
        """Initialize the email util.

        Args:
            sender (str): The email sender.
            recipient (str): The email recipient.
            auth (dict): A set of authentication attributes
            corresponding to the selected connector.
            custom (dict): A set of custom attributes.
        """
        self.sender = sender
        self.recipient = recipient
        if auth.get('api_key'):
            api_key = auth.get('api_key')
        # else block below is for backward compatibility
        else:
            api_key = auth.get('sendgrid_api_key')
        self.sendgrid = sendgrid.SendGridAPIClient(apikey=api_key)

        if custom:
            LOGGER.warning('Unable to process custom attributes: %s', custom) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:23,代碼來源:sendgrid_connector.py

示例4: send

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send(address, subject, template_name, context, for_real=False):

    templateLoader = jinja2.FileSystemLoader(searchpath="templates")
    templateEnv = jinja2.Environment(loader=templateLoader)
    html_template = templateEnv.get_template(template_name + ".html")

    html_to_send = html_template.render(context)

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
    from_email = Email("team@impactstory.org", "Impactstory team")
    to_email = Email(address)
    content = Content("text/html", html_to_send)
    mail = Mail(from_email, subject, to_email, content)

    if for_real:
        response = sg.client.mail.send.post(request_body=mail.get())
        print u"Sent an email to {}".format(address)
    else:
        print u"Didn't really send" 
開發者ID:ourresearch,項目名稱:impactstory-tng,代碼行數:21,代碼來源:emailer.py

示例5: send_email

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send_email(message):
    try:
        sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
        response = sg.send(message)
        print(response.status_code)
    except Exception as e:
        print("Deu erro na hora de enviar o email", str(e)) 
開發者ID:daniloaleixo,項目名稱:bovespaStockRatings,代碼行數:9,代碼來源:fundamentus.py

示例6: __init__

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def __init__(self, message: EmailMessage):
        self.mailer = SendGridAPIClient(api_key=os.environ['SENDGRID_API_KEY'])
        self.message = message 
開發者ID:MycroftAI,項目名稱:selene-backend,代碼行數:5,代碼來源:email.py

示例7: send

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send(email, for_real=False):
    if for_real:
        sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
        email_get = email.get()
        response = sg.client.mail.send.post(request_body=email_get)
        print u"Sent an email"
    else:
        print u"Didn't really send" 
開發者ID:ourresearch,項目名稱:oadoi,代碼行數:10,代碼來源:emailer.py

示例8: _send_report

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def _send_report(subject, report, to_address):
    content = Content("text/plain", report)
    from_email = Email("dev@ourresearch.org", "Unpaywall Team")
    to_email = Email(to_address)
    email = Mail(from_email, subject, to_email, content)

    tracking_settings = TrackingSettings()
    tracking_settings.click_tracking = ClickTracking(False, False)
    email.tracking_settings = tracking_settings

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
    sg.client.mail.send.post(request_body=email.get())

    logger.info(u'sent "{}" report to {}'.format(subject, to_address)) 
開發者ID:ourresearch,項目名稱:oadoi,代碼行數:16,代碼來源:scrape_regression_test.py

示例9: send

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send(to_email, subject, html_content):
  """Send email."""
  sendgrid_api_key = db_config.get_value('sendgrid_api_key')
  if not sendgrid_api_key:
    logs.log_warn('Skipping email as SendGrid API key is not set in config.')
    return

  from_email = db_config.get_value('sendgrid_sender')
  if not from_email:
    logs.log_warn('Skipping email as SendGrid sender is not set in config.')
    return

  message = Mail(
      from_email=From(str(from_email)),
      to_emails=To(str(to_email)),
      subject=Subject(subject),
      html_content=HtmlContent(str(html_content)))
  try:
    sg = SendGridAPIClient(sendgrid_api_key)
    response = sg.send(message)
    logs.log(
        'Sent email to %s.' % to_email,
        status_code=response.status_code,
        body=response.body,
        headers=response.headers)
  except Exception:
    logs.log_error('Failed to send email to %s.' % to_email) 
開發者ID:google,項目名稱:clusterfuzz,代碼行數:29,代碼來源:mail.py

示例10: __init__

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def __init__(self, apikey, from_email, to_email):
        self.sg = sendgrid.SendGridAPIClient(apikey=apikey)
        self.from_email = Email(from_email)
        self.to_email = Email(to_email) 
開發者ID:Urinx,項目名稱:WeixinBot,代碼行數:6,代碼來源:sendgrid_mail.py

示例11: _post_sendgrid_mail

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def _post_sendgrid_mail(mail_data):
    sendgrid_client = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
    response = sendgrid_client.client.mail.send.post(request_body=mail_data)
    # 2xx status code.
    if 200 <= response.status_code < 300:
        log.info('Email with subject %s is successfully sent to recipients: %s',
                 mail_data['subject'], mail_data['personalizations'])
    else:
        log.error('Failed to send out email with subject %s, status code: %s',
                  mail_data['subject'], response.status_code) 
開發者ID:apache,項目名稱:airflow,代碼行數:12,代碼來源:emailer.py

示例12: send_alerts

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send_alerts():
	limits_for_alert = get_limits_for_alert()
	if limits_for_alert:
		content = alert_email_body(limits_for_alert)
		recipients = [{'email': email} for email in settings.EMAIL_RECIPIENTS.split(',')]
		sg = sendgrid.SendGridAPIClient(api_key=settings.SENDGRID_API_KEY)
		data = {
			'content': [
				{
					'type': 'text/html',
					'value': '<html>{}</html>'.format(content)
				}
			],
			'from': {
					'email': settings.FROM_EMAIL_ADDRESS,
					'name': settings.FROM_EMAIL_NAME
				},
			'personalizations': [
				{
					'to': recipients
				}
			],
			'subject': "AWS Limit Alerts for ID {}".format(settings.ACCOUNT_ID),
		}
		sg.client.mail.send.post(request_body=data)
		save_sent_alerts(limits_for_alert) 
開發者ID:Yipit,項目名稱:awslimits,代碼行數:28,代碼來源:manage.py

示例13: __init__

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def __init__(self):
        # Check if we are not in heroku
        sendgrid_api_key = os.environ.get('SENDGRID_APY_KEY') if \
            os.environ.get('ENV') != 'prod' else os.environ['SENDGRID_API_KEY']
        self.sendgrid = sendgrid.SendGridAPIClient(apikey=sendgrid_api_key) 
開發者ID:sendgrid,項目名稱:open-source-library-data-collector,代碼行數:7,代碼來源:sendgrid_email.py

示例14: send_simple_message

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def send_simple_message(recipient):
    # [START sendgrid-send]
    message = Mail(
        from_email=SENDGRID_SENDER,
        to_emails='{},'.format(recipient),
        subject='This is a test email',
        html_content='<strong>Example</strong> message.')

    sg = sendgrid.SendGridAPIClient(SENDGRID_API_KEY)
    response = sg.send(message)

    return response
    # [END sendgrid-send] 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:15,代碼來源:main.py

示例15: load_secrets

# 需要導入模塊: import sendgrid [as 別名]
# 或者: from sendgrid import SendGridAPIClient [as 別名]
def load_secrets():
    if secrets is not None:
        return
    global secrets, send_grid_client, SENDGRID_SENDER
    secrets = json.loads(open("client_secrets.json").read())
    # TODO (rkwills) switch to a yelp sendgrid account
    send_grid_client = SendGridAPIClient(apikey=secrets["SENDGRID_API_KEY"])
    SENDGRID_SENDER = secrets["SENDGRID_SENDER"] 
開發者ID:Yelp,項目名稱:beans,代碼行數:10,代碼來源:send_email.py


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