Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

email_templates

Jugal Bhatt69670001de07
diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.md
index db011a5825c..5db76088fa6 100644
--- a/docs/my-website/docs/proxy/config_settings.md
+++ b/docs/my-website/docs/proxy/config_settings.md
@@ -434,6 +434,9 @@ router_settings:
| DOCS_URL | The path to the Swagger API documentation. **By default this is "/"**
| EMAIL_LOGO_URL | URL for the logo used in emails
| EMAIL_SUPPORT_CONTACT | Support contact email address
+| EMAIL_SIGNATURE | Custom signature for emails
+| EMAIL_SUBJECT_INVITATION | Custom subject template for invitation emails
+| EMAIL_SUBJECT_KEY_CREATED | Custom subject template for key creation emails
| EXPERIMENTAL_MULTI_INSTANCE_RATE_LIMITING | Flag to enable new multi-instance rate limiting. **Default is False**
| FIREWORKS_AI_4_B | Size parameter for Fireworks AI 4B model. Default is 4
| FIREWORKS_AI_16_B | Size parameter for Fireworks AI 16B model. Default is 16
diff --git a/docs/my-website/docs/proxy/email.md b/docs/my-website/docs/proxy/email.md
index 4eb35367dbe..5d5a07b156e 100644
--- a/docs/my-website/docs/proxy/email.md
+++ b/docs/my-website/docs/proxy/email.md
@@ -134,13 +134,20 @@ Customizing Email Branding is an Enterprise Feature [Get in touch with us for a
:::
-LiteLLM allows you to customize the:
+LiteLLM allows you to customize:
- Logo on the Email
-- Email support contact
+- Email support contact
+- Email signature
+- Email subject lines for different events
-Set the following in your env to customize your emails
+Set the following in your env to customize your emails:
```shell
EMAIL_LOGO_URL="https://litellm-listing.s3.amazonaws.com/litellm_logo.png" # public url to your logo
EMAIL_SUPPORT_CONTACT="[email protected]" # Your company support email
+EMAIL_SIGNATURE="Best regards,\nYour Company Team" # Custom email signature
+EMAIL_SUBJECT_INVITATION="Welcome to {company_name}!" # Subject for invitation emails
+EMAIL_SUBJECT_KEY_CREATED="Your API Key for {company_name}" # Subject for key creation emails
```
+
+If custom subject templates are not provided, the system will use default templates in the format "LiteLLM: {event_message}".
diff --git a/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py b/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py
index a7c127cffff..92ad14403b6 100644
--- a/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py
+++ b/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py
@@ -29,6 +29,10 @@ from litellm.types.integrations.slack_alerting import LITELLM_LOGO_URL
class BaseEmailLogger(CustomLogger):
DEFAULT_LITELLM_EMAIL = "[email protected]"
DEFAULT_SUPPORT_EMAIL = "[email protected]"
+ DEFAULT_SUBJECT_TEMPLATES = {
+ EmailEvent.new_user_invitation: "LiteLLM: {event_message}",
+ EmailEvent.virtual_key_created: "LiteLLM: {event_message}",
+ }
async def send_user_invitation_email(self, event: WebhookEvent):
"""
@@ -38,8 +42,8 @@ class BaseEmailLogger(CustomLogger):
email_event=EmailEvent.new_user_invitation,
user_id=event.user_id,
user_email=getattr(event, "user_email", None),
+ event_message=event.event_message,
)
- # Implement invitation email logic using email_params
verbose_proxy_logger.debug(
f"send_user_invitation_email_event: {json.dumps(event, indent=4, default=str)}"
@@ -50,13 +54,13 @@ class BaseEmailLogger(CustomLogger):
recipient_email=email_params.recipient_email,
base_url=email_params.base_url,
email_support_contact=email_params.support_contact,
- email_footer=EMAIL_FOOTER,
+ email_footer=email_params.signature,
)
await self.send_email(
from_email=self.DEFAULT_LITELLM_EMAIL,
to_email=[email_params.recipient_email],
- subject=f"LiteLLM: {event.event_message}",
+ subject=email_params.subject,
html_body=email_html_content,
)
@@ -68,11 +72,11 @@ class BaseEmailLogger(CustomLogger):
"""
Send email to user after creating key for the user
"""
-
email_params = await self._get_email_params(
user_id=send_key_created_email_event.user_id,
user_email=send_key_created_email_event.user_email,
email_event=EmailEvent.virtual_key_created,
+ event_message=send_key_created_email_event.event_message,
)
verbose_proxy_logger.debug(
@@ -86,13 +90,13 @@ class BaseEmailLogger(CustomLogger):
key_token=send_key_created_email_event.virtual_key,
base_url=email_params.base_url,
email_support_contact=email_params.support_contact,
- email_footer=EMAIL_FOOTER,
+ email_footer=email_params.signature,
)
await self.send_email(
from_email=self.DEFAULT_LITELLM_EMAIL,
to_email=[email_params.recipient_email],
- subject=f"LiteLLM: {send_key_created_email_event.event_message}",
+ subject=email_params.subject,
html_body=email_html_content,
)
pass
@@ -102,16 +106,34 @@ class BaseEmailLogger(CustomLogger):
email_event: EmailEvent,
user_id: Optional[str] = None,
user_email: Optional[str] = None,
+ event_message: Optional[str] = None,
) -> EmailParams:
"""
Get common email parameters used across different email sending methods
Returns:
- EmailParams object containing logo_url, support_contact, base_url, and recipient_email
+ EmailParams object containing logo_url, support_contact, base_url, recipient_email, subject, and signature
"""
logo_url = os.getenv("EMAIL_LOGO_URL", None) or LITELLM_LOGO_URL
support_contact = os.getenv("EMAIL_SUPPORT_CONTACT", self.DEFAULT_SUPPORT_EMAIL)
base_url = os.getenv("PROXY_BASE_URL", "http://0.0.0.0:4000")
+ signature = os.getenv("EMAIL_SIGNATURE", EMAIL_FOOTER)
+
+ # Get custom subject template based on email event type
+ if email_event == EmailEvent.new_user_invitation:
+ subject_template = os.getenv(
+ "EMAIL_SUBJECT_INVITATION",
+ self.DEFAULT_SUBJECT_TEMPLATES[EmailEvent.new_user_invitation]
+ )
+ elif email_event == EmailEvent.virtual_key_created:
+ subject_template = os.getenv(
+ "EMAIL_SUBJECT_KEY_CREATED",
+ self.DEFAULT_SUBJECT_TEMPLATES[EmailEvent.virtual_key_created]
+ )
+ else:
+ subject_template = "LiteLLM: {event_message}"
+
+ subject = subject_template.format(event_message=event_message) if event_message else "LiteLLM Notification"
recipient_email: Optional[
str
@@ -132,6 +154,8 @@ class BaseEmailLogger(CustomLogger):
support_contact=support_contact,
base_url=base_url,
recipient_email=recipient_email,
+ subject=subject,
+ signature=signature,
)
def _format_key_budget(self, max_budget: Optional[float]) -> str:
diff --git a/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py b/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py
index 95bc7ff94e9..3adeefa62bb 100644
--- a/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py
+++ b/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py
@@ -1,7 +1,6 @@
-import enum
-from typing import Dict, List
-
-from pydantic import BaseModel, Field
+from enum import Enum
+from typing import Dict, List, Optional
+from pydantic import BaseModel
from litellm.proxy._types import WebhookEvent
@@ -11,6 +10,8 @@ class EmailParams(BaseModel):
support_contact: str
base_url: str
recipient_email: str
+ subject: str
+ signature: str
class SendKeyCreatedEmailEvent(WebhookEvent):
@@ -22,7 +23,7 @@ class SendKeyCreatedEmailEvent(WebhookEvent):
"""
-class EmailEvent(str, enum.Enum):
+class EmailEvent(str, Enum):
virtual_key_created = "Virtual Key Created"
new_user_invitation = "New User Invitation"