EmailService class

The central email sending service.

EmailService is a singleton that wraps any EmailProvider and exposes a simple send method. Configure it once at startup:

EmailService.instance.configure(
  provider: SendGridProvider(
    apiKey: Env.sendgridApiKey,
    fromEmail: 'noreply@example.com',
  ),
);

// Later:
final result = await EmailService.instance.send(
  EmailMessage(
    to: 'user@example.com',
    subject: 'Hello!',
    htmlBody: '<p>Welcome aboard.</p>',
  ),
);

Properties

hashCode int
The hash code for this object.
no setterinherited
isConfigured bool
Returns true if configure has been called.
no setter
providerName String?
The name of the active provider, or null if not configured.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

configure({required EmailProvider provider}) → void
Configures the service with the given provider.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetForTesting() → void
Resets the service to its unconfigured state.
send(EmailMessage message) Future<EmailResult>
Sends message using the configured provider.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance EmailService
The shared singleton instance.
no setter