Skip to content

Commit d06ddd8

Browse files
committed
docs: improve email client documentation
- Updated `HtEmailClient` description. - Clarified usage instructions. - Improved example code clarity. - Removed outdated `sendOtpEmail` method. - Added note about concrete implementations.
1 parent fa299b0 commit d06ddd8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,41 @@ Then run `dart pub get`.
2323

2424
## Features
2525

26-
* **`HtEmailClient` Abstract Class:** Defines the core interface for email sending operations.
27-
* `Future<void> sendOtpEmail({required String recipientEmail, required String otpCode})`: Sends a One-Time Password email. Implementations must handle underlying service errors and map them to standard `ht_shared` exceptions.
26+
* **`HtEmailClient` Abstract Class:** Defines a generic, provider-agnostic interface for sending transactional emails. This approach decouples application logic from email content and styling, which can be managed directly within your email service provider (e.g., SendGrid, AWS SES).
27+
* `Future<void> sendTransactionalEmail({required String recipientEmail, required String templateId, required Map<String, dynamic> templateData})`: Sends an email using a pre-defined template. Implementations must handle underlying service errors and map them to standard `ht_shared` exceptions.
2828

2929
## Usage
3030

31-
This package only provides the abstract interface. You need a concrete implementation package that implements `HtEmailClient`.
31+
This package only provides the abstract interface. You need a concrete implementation package (e.g., `ht_email_sendgrid`) that implements `HtEmailClient`.
3232

3333
In your backend application (e.g., Dart Frog), you would typically:
3434

35-
1. Depend on a concrete implementation package (e.g., `ht_email_client_smtp`).
36-
2. Configure and provide an instance of the concrete client using dependency injection (e.g., Dart Frog's provider).
37-
3. Inject `HtEmailClient` into your services or route handlers where email sending is required.
35+
1. Depend on a concrete implementation package.
36+
2. Configure and provide an instance of the concrete client using dependency injection.
37+
3. Inject `HtEmailClient` into your services where email sending is required.
3838

3939
```dart
4040
// Example (Conceptual - in a service or route handler)
4141
import 'package:ht_email_client/ht_email_client.dart';
42-
import 'package:ht_shared/ht_shared.dart'; // For User model
42+
import 'package:ht_shared/ht_shared.dart';
4343
4444
class AuthService {
4545
const AuthService({required HtEmailClient emailClient})
4646
: _emailClient = emailClient;
4747
4848
final HtEmailClient _emailClient;
4949
50-
Future<void> sendVerificationEmail(User user, String otp) async {
51-
if (user.email == null) {
52-
throw InvalidInputException('User email is missing.');
53-
}
50+
Future<void> sendVerificationEmail(String email, String otp) async {
5451
try {
55-
await _emailClient.sendOtpEmail(
56-
recipientEmail: user.email!,
57-
otpCode: otp,
52+
// Use the generic method to send an email via a template.
53+
// The template ID and data structure are managed by the email provider.
54+
await _emailClient.sendTransactionalEmail(
55+
recipientEmail: email,
56+
templateId: 'd-1234567890abcdef1234567890abcdef', // Example SendGrid Template ID
57+
templateData: {
58+
'otp_code': otp,
59+
'username': 'Valued User',
60+
},
5861
);
5962
// Handle success
6063
} on HtHttpException {

0 commit comments

Comments
 (0)