Exemple #1
0
import nats
from aiosmtplib import SMTP
from entity_queue_common.service import QueueServiceManager
from entity_queue_common.service_utils import QueueException
from notify_api import NotifyAPI
from notify_api.db.models.notification import Notification, NotificationUpdate
from notify_api.db.models.notification_status import NotificationStatusEnum
from notify_api.services.notify import NotifyService

from notify_service import config as app_config

# setup loggers
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger(__name__)

qsm = QueueServiceManager()  # pylint: disable=invalid-name
APP = NotifyAPI(bind=app_config.SQLALCHEMY_DATABASE_URI)


async def send_with_send_message(message, recipients):
    """Send email."""
    try:
        smtp_client = SMTP(hostname=app_config.MAIL_SERVER,
                           port=app_config.MAIL_PORT)
        await smtp_client.connect()
        await smtp_client.send_message(message=message, recipients=recipients)
        await smtp_client.quit()
    except Exception as err:  # pylint: disable=broad-except # noqa F841;
        logger.error('Notify Job (send_with_send_message) Error: %s', err)
        return False
    return True