当前位置: 首页>>代码示例>>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;未经允许,请勿转载。