masamune_mail 3.2.0 copy "masamune_mail: ^3.2.0" to clipboard
masamune_mail: ^3.2.0 copied to clipboard

Plug-in for sending emails via Sendgrid, etc. from servers, etc. using Functions.

Masamune logo

Masamune Mail

Follow on GitHub Follow on X Follow on YouTube Maintained with Melos

GitHub Sponsor


[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]


Masamune Mail #

Usage #

Installation #

Add the package to your project.

flutter pub add masamune_mail

Run flutter pub get when editing pubspec.yaml manually.

Register the Adapter #

Register MailMasamuneAdapter before running the app. Combine it with a Functions adapter that can call your backend email endpoints.

// lib/adapter.dart

/// Masamune adapters used by the application.
final masamuneAdapters = <MasamuneAdapter>[
  const UniversalMasamuneAdapter(),

  const MailMasamuneAdapter(),
];

MailMasamuneAdapter.primary exposes the adapter instance when needed.

Send Email via Cloud Functions #

This package provides FunctionsAction classes to send emails through your backend. Your backend must implement the actual email sending logic using SendGrid, or other email service providers.

SendGrid Example:

import 'package:masamune_functions/masamune_functions.dart';
import 'package:masamune_mail/masamune_mail.dart';

// In your controller or page
final functions = ref.app.functions();

Future<void> sendWelcomeEmail(String userEmail) async {
  try {
    await functions.execute(
      SendGridFunctionsAction(
        from: "support@example.com",
        to: userEmail,
        title: "Welcome!",
        content: "Thank you for signing up. We're excited to have you!",
      ),
    );
    print("Email sent successfully");
  } catch (e) {
    print("Failed to send email: $e");
  }
}

Backend Implementation #

Your Masamune Functions backend must handle the send_grid actions:

SendGrid Backend Example:

// Cloud Functions
if (action === "send_grid") {
  const { from, to, title, content } = data;
  
  // Use SendGrid SDK
  await sendgrid.send({
    to: to,
    from: from,
    subject: title,
    text: content,
  });
  
  return { success: true };
}

Tips #

  • Store API keys (SendGrid) securely using environment variables or secret managers.
  • Add validation and rate limiting to your backend endpoints to prevent abuse.
  • Log email sends for audit purposes and monitor for delivery issues.

GitHub Sponsors #

Sponsors are always welcome. Thank you for your support!

https://github.com/sponsors/mathrunet

0
likes
150
points
503
downloads

Publisher

verified publishermathru.net

Weekly Downloads

Plug-in for sending emails via Sendgrid, etc. from servers, etc. using Functions.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, katana, masamune

More

Packages that depend on masamune_mail