MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / EmailSender

Class EmailSender

keepercommander/email_service.py:985–1056  ·  view source on GitHub ↗

Main email sender class that routes to appropriate provider. Usage: config = EmailConfig(...) sender = EmailSender(config) sender.send(to='user@example.com', subject='Test', body='Hello', html=True)

Source from the content-addressed store, hash-verified

983
984
985class EmailSender:
986 """
987 Main email sender class that routes to appropriate provider.
988
989 Usage:
990 config = EmailConfig(...)
991 sender = EmailSender(config)
992 sender.send(to='user@example.com', subject='Test', body='Hello', html=True)
993 """
994
995 def __init__(self, config: EmailConfig):
996 """
997 Initialize email sender with configuration.
998
999 Args:
1000 config: EmailConfig object
1001
1002 Raises:
1003 ValueError: If provider is unknown or config invalid
1004 """
1005 self.config = config
1006
1007 # Check provider compatibility with current installation
1008 dependencies_available, error_message = check_provider_dependencies(config.provider)
1009 if not dependencies_available:
1010 raise ValueError(error_message)
1011
1012 # Create provider instance
1013 provider_map = {
1014 'smtp': SMTPEmailProvider,
1015 'sendgrid': SendGridEmailProvider,
1016 'ses': SESEmailProvider,
1017 'gmail-oauth': GmailOAuthProvider,
1018 'microsoft-oauth': MicrosoftOAuthProvider,
1019 }
1020
1021 provider_class = provider_map.get(config.provider.lower())
1022 if not provider_class:
1023 raise ValueError(
1024 f"Unknown email provider: {config.provider}. "
1025 f"Supported: {', '.join(provider_map.keys())}"
1026 )
1027
1028 self.provider = provider_class(config)
1029
1030 def send(self, to: str, subject: str, body: str, html: bool = False) -> bool:
1031 """
1032 Send email via configured provider.
1033
1034 Args:
1035 to: Recipient email address
1036 subject: Email subject
1037 body: Email body
1038 html: True if body is HTML
1039
1040 Returns:
1041 True if sent successfully
1042

Calls

no outgoing calls