Skip to content

A concrete implementation of the EmailClient interface that uses the SendGrid API to send transactional emails.

Notifications You must be signed in to change notification settings

flutter-news-app-full-source-code/email-sendgrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

email_sendgrid

coverage: percentage style: very good analysis License: PolyForm Free Trial

A concrete implementation of the EmailClient interface that uses the SendGrid API to send transactional emails.

Description

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.

Getting Started

Add the dependency to your pubspec.yaml:

dependencies:
  email_sendgrid:
    git:
      url: https://github.com/flutter-news-app-full-source-code/email-sendgrid.git
      # ref: <specific_tag_or_commit>

Usage

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.

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: '[email protected]',
      recipientEmail: '[email protected]',
      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');
  }
}

🔑 Licensing

This package is source-available and licensed under the PolyForm Free Trial 1.0.0. 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 organization.

About

A concrete implementation of the EmailClient interface that uses the SendGrid API to send transactional emails.

Resources

Stars

Watchers

Forks

Languages