搜索插件、代码仓与 APP 分类

插件详情v3.0.3

flutter_mailer

将电子邮件分享到设备 邮件 - 客户端支持多个附件

AndroidiOS
近 30 天下载
2.9万
喜欢数
92
Pub 分数
160

安装插件

flutter pub add flutter_mailer

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flutter Mailer 是一个 Flutter 包,可让用户直接从其应用程序将邮件分享到设备的默认邮件客户端。它支持发送带有多个附件的邮件,非常适合共享文档、图片或其他文件。该包可无缝集成到 Android 和 iOS 平台,利用原生邮件意图确保兼容性和可靠性。它简化了启动邮件编辑界面的过程,可预设收件人、主题、正文和附件。

适合场景

  • 从应用内共享文档
  • 发送带附件的支持工单
  • 分发报告或收据
  • 通过电子邮件启用用户反馈
  • 在应用中自动化电子邮件工作流程

主要特点

  • 支持多个文件附件
  • 在 Android 和 iOS 上使用原生邮件客户端
  • 电子邮件编写的简单 API
  • 跨平台兼容性
  • 可配置的电子邮件字段(收件人、主题、正文)

适合对象

  • 需要电子邮件共享功能的应用程序
  • 基于文档的应用程序
  • 客户支持集成
  • 报告或分析工具
  • 用户生成内容分发

使用建议

  • 依赖用户的默认电子邮件客户端
  • 没有用户交互,无法直接发送电子邮件
  • 附件大小限制取决于设备和操作系统
  • 某些设备需要正确的权限
  • 电子邮件的编写方式在不同平台上可能略有差异

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_mailer

pub package

Share email content via device Email Client - supports multiple Attachments

Simple & quick plugin for cross application data sharing of email fields in mobile development.

Flutter Mailer example app

Supports:

  • [x] android
  • [x] ios

Getting Started

Add to your pubspec dependencies, like so:

dependencies:
  flutter:
    sdk: flutter
  flutter_mailer: ^3.0.0

Instantiate mail options as follows:

send email
import 'package:flutter_mailer/flutter_mailer.dart';

...
...

final MailOptions mailOptions = MailOptions(
  body: 'a long body for the email <br> with a subset of HTML',
  subject: 'the Email Subject',
  recipients: ['example@example.com'],
  isHTML: true,
  bccRecipients: ['other@example.com'],
  ccRecipients: ['third@example.com'],
  attachments: [ 'path/to/image.png', ],
);

final MailerResponse response = await FlutterMailer.send(mailOptions);
switch (response) {
  case MailerResponse.saved: /// ios only
    platformResponse = 'mail was saved to draft';
    break;
  case MailerResponse.sent: /// ios only
    platformResponse = 'mail was sent';
    break;
  case MailerResponse.cancelled: /// ios only
    platformResponse = 'mail was cancelled';
    break;
  case MailerResponse.android:
    platformResponse = 'intent was successful';
    break;
  default:
    platformResponse = 'unknown';
    break;
}

note gmail and other apps Might parse HTML out of the body.

[Android] check if app is installed.

use full if you want to send the intent to a specific App. returns false on [IOS]

const GMAIL_SCHEMA = 'com.google.android.gm';

final bool gmailinstalled =  await FlutterMailer.isAppInstalled(GMAIL_SCHEMA);

if(gmailinstalled) {
  final MailOptions mailOptions = MailOptions(
    body: 'a long body for the email <br> with a subset of HTML',
    subject: 'the Email Subject',
    recipients: ['example@example.com'],
    isHTML: true,
    bccRecipients: ['other@example.com'],
    ccRecipients: ['third@example.com'],
    attachments: [ 'path/to/image.png', ],
    appSchema: GMAIL_SCHEMA,
  );
  await FlutterMailer.send(mailOptions);
}

[IOS] check if device has the ability to send email

this package uses MFMailComposeViewController for [IOS] which requires the default mail App. if none is installed you might want to revert to use url_launcher returns false on [Android]


  final bool canSend = await FlutterMailer.canSendMail();

  if(!canSend && Platform.isIos) {
    final url = 'mailto:$recipient?body=$body&subject=$subject';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}

For help getting started with Flutter, view official online documentation.

For help on editing plugin code, view the documentation.

based off of react-native-mail

所属分类

源码仓库

使用此插件的项目