File size: 1,130 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
This is the litellm SMTP email integration
"""
import asyncio
from typing import List

from litellm._logging import verbose_logger

from .base_email import BaseEmailLogger


class SMTPEmailLogger(BaseEmailLogger):
    """
    This is the litellm SMTP email integration

    Required SMTP environment variables:
    - SMTP_HOST
    - SMTP_PORT
    - SMTP_USERNAME
    - SMTP_PASSWORD
    - SMTP_SENDER_EMAIL
    """

    def __init__(self):
        verbose_logger.debug("SMTP Email Logger initialized....")

    async def send_email(
        self,
        from_email: str,
        to_email: List[str],
        subject: str,
        html_body: str,
    ):
        from litellm.proxy.utils import send_email as send_smtp_email

        verbose_logger.debug(
            f"Sending email from {from_email} to {to_email} with subject {subject}"
        )
        for receiver_email in to_email:
            asyncio.create_task(
                send_smtp_email(
                    receiver_email=receiver_email,
                    subject=subject,
                    html=html_body,
                )
            )
        return