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


Python sendgrid.Mail方法代码示例

本文整理汇总了Python中sendgrid.Mail方法的典型用法代码示例。如果您正苦于以下问题:Python sendgrid.Mail方法的具体用法?Python sendgrid.Mail怎么用?Python sendgrid.Mail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sendgrid的用法示例。


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

示例1: send_email

# 需要导入模块: import sendgrid [as 别名]
# 或者: from sendgrid import Mail [as 别名]
def send_email(routes_to_report):
    """Send email using sendgrid."""
    number_of_routes = len(routes_to_report)
    if number_of_routes == 0:
        return False

    formatted_date = dt.datetime.utcnow().strftime("%A, %b %d")
    rich_email_body = render_template(
        "email.html",
        routes=routes_to_report,
        date=formatted_date
    )

    sg = SendGridClient(config.SG_USERNAME, config.SG_PASSWORD, raise_errors=True)

    formatted_time = dt.datetime.utcnow().strftime("%F %T")
    subject = '({}): {} routes'
    subject = subject.format(formatted_time, number_of_routes)

    try:
        message = Mail(
            to=config.TO_EMAIL,
            subject=subject,
            html=rich_email_body,
            from_email=config.FROM_EMAIL
        )

        status, msg = sg.send(message)
        return msg
    except SendGridClientError as e:
        print 'Failed to send email: ', e
        raise 
开发者ID:uber,项目名称:focuson,代码行数:34,代码来源:mail.py

示例2: Memail

# 需要导入模块: import sendgrid [as 别名]
# 或者: from sendgrid import Mail [as 别名]
def Memail(mto, mfrom, msubject, mbody, email_template_name, context):
    if settings.MAIL_SENDER == 'AMAZON':
        sending_mail(msubject, email_template_name, context, mfrom, mto)
    elif settings.MAIL_SENDER == 'MAILGUN':
        requests.post(
            settings.MGUN_API_URL,
            auth=('api', settings.MGUN_API_KEY),
            data={
                'from': mfrom,
                'to': mto,
                'subject': msubject,
                'html': mbody
            })
    elif settings.MAIL_SENDER == 'SENDGRID':
        sg = sendgrid.SendGridClient(settings.SG_USER, settings.SG_PWD)
        sending_msg = sendgrid.Mail()
        sending_msg.set_subject(msubject)
        sending_msg.set_html(mbody)
        sending_msg.set_text(msubject)
        sending_msg.set_from(mfrom)
        sending_msg.add_to(mto)
        reposne = sg.send(sending_msg)
        print (reposne)
    else:
        text_content = msubject
        msg = EmailMultiAlternatives(msubject, mbody, mfrom, mto)
        msg.attach_alternative(mbody, "text/html")
        msg.send() 
开发者ID:MicroPyramid,项目名称:django-simple-forum,代码行数:30,代码来源:sending_mail.py

示例3: _send_to_sendgrid

# 需要导入模块: import sendgrid [as 别名]
# 或者: from sendgrid import Mail [as 别名]
def _send_to_sendgrid(self, message, email_addresses, cc=None, bcc=None,
                          sender=None):
        username = (base.secret('sendgrid_low_priority_username') or
                    base.secret('sendgrid_username'))
        password = (base.secret('sendgrid_low_priority_password') or
                    base.secret('sendgrid_password'))
        assert username and password, "Can't find sendgrid username/password"
        client = sendgrid.SendGridClient(username, password, raise_errors=True)

        # The sendgrid API client auto-utf8-izes to/cc/bcc, but not
        # subject/text.  Shrug.
        msg = sendgrid.Mail(
            subject=self._get_summary().encode('utf-8'),
            to=email_addresses,
            cc=cc,
            bcc=bcc)
        if self.html:
            # TODO(csilvers): convert the html to text for 'body'.
            # (see base.py about using html2text or similar).
            msg.set_text(message.encode('utf-8'))
            msg.set_html(message.encode('utf-8'))
        else:
            msg.set_text(message.encode('utf-8'))
        # Can't be keyword arg because those don't parse "Name <email>"
        # format.
        msg.set_from(_get_sender(sender))

        client.send(msg) 
开发者ID:Khan,项目名称:alertlib,代码行数:30,代码来源:email.py

示例4: compose

# 需要导入模块: import sendgrid [as 别名]
# 或者: from sendgrid import Mail [as 别名]
def compose(sender, recipient, subject, text="", html="None"):
        """
        RECOMMENDED: use this method to compose the email.

        Returns: A mail instance.
        """
        message = sendgrid.Mail()
        message.add_to(recipient)
        message.set_subject(subject)
        message.set_html(html)
        message.set_text(text)
        message.set_from(sender)

        return message 
开发者ID:andela,项目名称:troupon,代码行数:16,代码来源:emails.py

示例5: publish_diff

# 需要导入模块: import sendgrid [as 别名]
# 或者: from sendgrid import Mail [as 别名]
def publish_diff(self, diff, feed_config):
        if diff.emailed:
            raise AlreadyEmailedError(diff.id)
        elif not (diff.old.archive_url and diff.new.archive_url):
            raise SendgridArchiveUrlNotFoundError()

        api_token = feed_config.get("api_token", self.api_token)
        sender = feed_config.get("sender", self.sender)

        recipients = None
        if feed_config.get("recipients"):
            recipients = self.build_recipients(feed_config.get("recipients"))
        else:
            recipients = self.recipients
        if not all([api_token, sender, recipients]):
            raise SendgridConfigNotFoundError

        subject = self.build_subject(diff)
        message = Mail(
            from_email=sender,
            subject=subject,
            to_emails=recipients.pop(0),
            html_content=self.build_html_body(diff),
        )
        if recipients:
            message.bcc = recipients
        try:
            self.mailer(api_token).send(message)
            diff.emailed = datetime.utcnow()
            logging.info("emailed %s", subject)
            diff.save()
        except Exception as e:
            logging.error("unable to email: %s", e) 
开发者ID:DocNow,项目名称:diffengine,代码行数:35,代码来源:sendgrid.py


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