Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
pubspec.lock
coverage/
84 changes: 27 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,41 @@
# email_sendgrid
<div align="center">
<img src="https://avatars.githubusercontent.com/u/202675624?s=400&u=dc72a2b53e8158956a3b672f8e52e39394b6b610&v=4" alt="Flutter News App Toolkit Logo" width="220">
<h1>Email SendGrid</h1>
<p><strong>A concrete implementation of the `EmailClient` interface using the SendGrid API for the Flutter News App Toolkit.</strong></p>
</div>

![coverage: percentage](https://img.shields.io/badge/coverage-100-green)
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
<p align="center">
<img src="https://img.shields.io/badge/coverage-100%25-green?style=for-the-badge" alt="coverage">
<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>
<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>
</p>

A concrete implementation of the `EmailClient` interface that uses the SendGrid API to send transactional emails.
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 that require integration with a powerful email service provider.

## Description
## ⭐ Feature Showcase: Reliable SendGrid Email Integration

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.
This package offers a comprehensive set of features for integrating with the SendGrid API.

## Getting Started
<details>
<summary><strong>🧱 Core Functionality</strong></summary>

Add the dependency to your `pubspec.yaml`:
### 🚀 `EmailClient` Implementation
- **`EmailSendGrid` Class:** A concrete implementation of the `EmailClient` interface, providing a standardized way to send emails via SendGrid.
- **SendGrid API Integration:** Connects directly to the SendGrid v3 API for sending transactional emails, ensuring reliable delivery.

```yaml
dependencies:
email_sendgrid:
git:
url: https://github.com/flutter-news-app-full-source-code/email-sendgrid.git
# ref: <specific_tag_or_commit>
```
### 🌐 Template-Based Email Sending
- **`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.

## Usage
### 🛡️ Integrated Error Handling
- **`HttpClient` & `HttpException`:** Leverages the `http_client` package for underlying HTTP communication and propagates standardized `HttpException` errors (from `core`), ensuring consistent and predictable error management.

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.
### 💉 Dependency Injection Ready
- **`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.

```dart
import 'package:dio/dio.dart';
import 'package:email_client/email-client.dart';
import 'package:email_sendgrid/email_sendgrid.dart';
import 'package:http_client/http_client.dart';
import 'package:logging/logging.dart';
void main() async {
// 1. Configure the HttpClient for SendGrid
final sendGridHttpClient = HttpClient(
baseUrl: 'https://api.sendgrid.com/v3',
tokenProvider: () async => 'YOUR_SENDGRID_API_KEY', // Provide your key here
isWeb: false, // Use false for server-side applications
);
// 2. Instantiate the SendGrid email client
final EmailClient emailClient = EmailSendGrid(
httpClient: sendGridHttpClient,
log: Logger('SendGridClient'),
);
// 3. Use the client to send an email
try {
await emailClient.sendTransactionalEmail(
senderEmail: 'noreply@yourdomain.com',
recipientEmail: 'recipient@example.com',
subject: 'Your Subject Here',
templateId: 'd-your-template-id',
templateData: {'name': 'World'},
);
print('Email sent successfully!');
} on HttpException catch (e) {
print('Failed to send email: $e');
}
}
```
> **💡 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.
</details>

## 🔑 Licensing

This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use.

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.
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.
20 changes: 0 additions & 20 deletions coverage/lcov.info

This file was deleted.

Loading
Loading