def send_expiration_notifications(exclude, disabled_notification_plugins, disable_security_team_emails=False):
    """
    This function will check for upcoming certificate expiration,
    and send out notification emails at given intervals.
    """
    success = failure = 0

    # security team gets all expiration emails (if enabled)
    security_email = current_app.config.get("LEMUR_SECURITY_TEAM_EMAIL")
    # if disabled, don't explicitly include the security team here
    # note that you will ALSO need to disable the DEFAULT_SECURITY_X_DAY notifications to truly turn these off
    if disable_security_team_emails:
        security_email = []

    for owner, notification_group in get_eligible_certificates(exclude=exclude).items():

        for notification_label, certificates in notification_group.items():
            notification_data = []
            cert_ids = []

            notification = certificates[0][0]

            # skip sending the notification if the plugin is marked as disabled
            if notification.plugin.slug not in disabled_notification_plugins:

                for data in certificates:
                    n, certificate = data
                    cert_data = certificate_notification_output_schema.dump(
                        certificate
                    ).data
                    notification_data.append(cert_data)
                    cert_ids.append(certificate.id)

                email_recipients = notification.plugin.get_recipients(notification.options, security_email + [owner])
                email_tags = {"cert_ids": cert_ids, "notification_id": notification.id,
                              "notification_label": notification.label}
                # Plugin will ONLY use the provided recipients if it's email; any other notification plugin ignores them
                if send_plugin_notification(
                        "expiration", notification_data, email_recipients, notification, email_tags=email_tags
                ):
                    success += len(email_recipients)
                else:
                    failure += len(email_recipients)
                # If we're using an email plugin, we're done,
                #   since "security_email + [owner]" were added as email_recipients.
                # If we're not using an email plugin, we also need to send an email to the security team and owner,
                #   since the plugin notification didn't send anything to them.
                if notification.plugin.slug != "email-notification":
                    # If the plugin wasn't email, it only sent one notification, so set the success/failure
                    # to the correct value (1) at this point
                    if success:
                        success, failure = 1, 0
                    else:
                        success, failure = 0, 1
                    # If email-notification plugin is disabled, we won't sent these extra notifications.
                    if "email-notification" not in disabled_notification_plugins:
                        if send_default_notification(
                                "expiration", notification_data, email_recipients, notification.options,
                                email_tags=email_tags
                        ):
                            success += len(email_recipients)
                        else:
                            failure += len(email_recipients)

    return success, failure

    This function will check for upcoming certificate expiration,
    and send out notification emails at given intervals.
    
lemur/notifications/messaging.py