|
1 | | -# email_sendgrid |
| 1 | +<div align="center"> |
| 2 | + <img src="https://avatars.githubusercontent.com/u/202675624?s=400&u=dc72a2b53e8158956a3b672f8e52e39394b6b610&v=4" alt="Flutter News App Toolkit Logo" width="220"> |
| 3 | + <h1>Email SendGrid</h1> |
| 4 | + <p><strong>A concrete implementation of the `EmailClient` interface using the SendGrid API for the Flutter News App Toolkit.</strong></p> |
| 5 | +</div> |
2 | 6 |
|
3 | | - |
4 | | -[](https://pub.dev/packages/very_good_analysis) |
5 | | -[](https://polyformproject.org/licenses/free-trial/1.0.0) |
| 7 | +<p align="center"> |
| 8 | + <img src="https://img.shields.io/badge/coverage-100%25-green?style=for-the-badge" alt="coverage"> |
| 9 | + <a href="https://flutter-news-app-full-source-code.github.io/docs/"><img src="https://img.shields.io/badge/LIVE_DOCS-VIEW-slategray?style=for-the-badge" alt="Live Docs: View"></a> |
| 10 | + <a href="https://github.com/flutter-news-app-full-source-code"><img src="https://img.shields.io/badge/MAIN_PROJECT-BROWSE-purple?style=for-the-badge" alt="Main Project: Browse"></a> |
| 11 | +</p> |
6 | 12 |
|
7 | | -A concrete implementation of the `EmailClient` interface that uses the SendGrid API to send transactional emails. |
| 13 | +This `email_sendgrid` package provides a concrete implementation of the `EmailClient` interface within the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). It leverages the SendGrid v3 API to send transactional emails, offering a robust and reliable solution for email dispatch. Designed to be used with the `email_repository` and `http_client` packages, it utilizes the standardized `HttpClient` for making HTTP requests and handling errors, ensuring consistent behavior and robust error management. This package is crucial for backend services (like a Dart Frog API) that require integration with a powerful email service provider. |
8 | 14 |
|
9 | | -## Description |
| 15 | +## ⭐ Feature Showcase: Reliable SendGrid Email Integration |
10 | 16 |
|
11 | | -This package provides `EmailSendGrid`, a class that connects to the SendGrid v3 API to send emails. It is designed to be used with the `email_repository` and `http_client` packages, leveraging the standardized `HttpClient` for making HTTP requests and handling errors. |
| 17 | +This package offers a comprehensive set of features for integrating with the SendGrid API. |
12 | 18 |
|
13 | | -## Getting Started |
| 19 | +<details> |
| 20 | +<summary><strong>🧱 Core Functionality</strong></summary> |
14 | 21 |
|
15 | | -Add the dependency to your `pubspec.yaml`: |
| 22 | +### 🚀 `EmailClient` Implementation |
| 23 | +- **`EmailSendGrid` Class:** A concrete implementation of the `EmailClient` interface, providing a standardized way to send emails via SendGrid. |
| 24 | +- **SendGrid API Integration:** Connects directly to the SendGrid v3 API for sending transactional emails, ensuring reliable delivery. |
16 | 25 |
|
17 | | -```yaml |
18 | | -dependencies: |
19 | | - email_sendgrid: |
20 | | - git: |
21 | | - url: https://github.com/flutter-news-app-full-source-code/email-sendgrid.git |
22 | | - # ref: <specific_tag_or_commit> |
23 | | -``` |
| 26 | +### 🌐 Template-Based Email Sending |
| 27 | +- **`sendTransactionalEmail` Method:** Supports sending emails using pre-defined SendGrid templates, allowing for dynamic content injection via `templateData`. This decouples email content and styling from application logic. |
24 | 28 |
|
25 | | -## Usage |
| 29 | +### 🛡️ Integrated Error Handling |
| 30 | +- **`HttpClient` & `HttpException`:** Leverages the `http_client` package for underlying HTTP communication and propagates standardized `HttpException` errors (from `core`), ensuring consistent and predictable error management. |
26 | 31 |
|
27 | | -To use this client, you must first configure an `HttpClient` instance with the SendGrid API base URL and an `AuthInterceptor` that provides your SendGrid API key. |
| 32 | +### 💉 Dependency Injection Ready |
| 33 | +- **`HttpClient` Dependency:** Requires an instance of `HttpClient` (from the `http_client` package) configured with the SendGrid API base URL and API key, promoting loose coupling and testability. |
28 | 34 |
|
29 | | -```dart |
30 | | -import 'package:dio/dio.dart'; |
31 | | -import 'package:email_client/email-client.dart'; |
32 | | -import 'package:email_sendgrid/email_sendgrid.dart'; |
33 | | -import 'package:http_client/http_client.dart'; |
34 | | -import 'package:logging/logging.dart'; |
35 | | -
|
36 | | -void main() async { |
37 | | - // 1. Configure the HttpClient for SendGrid |
38 | | - final sendGridHttpClient = HttpClient( |
39 | | - baseUrl: 'https://api.sendgrid.com/v3', |
40 | | - tokenProvider: () async => 'YOUR_SENDGRID_API_KEY', // Provide your key here |
41 | | - isWeb: false, // Use false for server-side applications |
42 | | - ); |
43 | | -
|
44 | | - // 2. Instantiate the SendGrid email client |
45 | | - final EmailClient emailClient = EmailSendGrid( |
46 | | - httpClient: sendGridHttpClient, |
47 | | - log: Logger('SendGridClient'), |
48 | | - ); |
49 | | -
|
50 | | - // 3. Use the client to send an email |
51 | | - try { |
52 | | - await emailClient.sendTransactionalEmail( |
53 | | - |
54 | | - recipientEmail: '[email protected]', |
55 | | - subject: 'Your Subject Here', |
56 | | - templateId: 'd-your-template-id', |
57 | | - templateData: {'name': 'World'}, |
58 | | - ); |
59 | | - print('Email sent successfully!'); |
60 | | - } on HttpException catch (e) { |
61 | | - print('Failed to send email: $e'); |
62 | | - } |
63 | | -} |
64 | | -``` |
| 35 | +> **💡 Your Advantage:** This package provides a robust and production-ready SendGrid integration for your email sending needs. It simplifies the process of sending transactional emails, leverages standardized error handling, and integrates seamlessly with the existing `http_client` and `email_client` architecture. |
65 | 36 |
|
| 37 | +</details> |
66 | 38 |
|
67 | 39 | ## 🔑 Licensing |
68 | 40 |
|
69 | | -This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use. |
70 | | - |
71 | | -For commercial licensing options that grant the right to build and distribute unlimited applications, please visit the main [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code) organization. |
| 41 | +This `email_sendgrid` package is an integral part of the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the main toolkit organization page. |
0 commit comments