paulstelzer / capacitor-email-composer

E-Mail Composer Plugin for Capacitor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capacitor E-Mail Composer

Maintenance npm

This Plugin is used to open a native E-Mail Composer within your Capacitor App.

Donate

This and other Open-Source Cordova/Capacitor Plugins are developed in my free time. To help ensure this plugin is kept updated, new features are added and bugfixes are implemented quickly, please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance. Please consider donating if you're using this plugin in an app that makes you money, if you're being paid to make the app, if you're asking for new features or priority bug fixes.

Table of Content

Install

npm install capacitor-email-composer
npx cap sync

Attachments

You can add attachments to the draft mail by using the attachments option in the open(...) method. Every attachment needs a type and a path. If you are adding a base64 type attachment, you also need to set the name:

Device Storage

The path to the files must be defined absolute from the root of the file system. On Android the user has to allow the app first to read from external storage!

EmailComposerPlugin.open({
  attachments: [{
    type: 'absolute',
    path: 'storage/sdcard/icon.png' // Android
  }]
})

Native resources

Each app has a resource folder, e.g. the res folder for Android apps or the Resource folder for iOS apps. The following example shows how to attach the app icon from within the app's resource folder.

EmailComposerPlugin.open({
  attachments: [{
    type: 'resource',
    path: 'icon.png'
  }]
})

Assets

The path to the files must be defined relative from the root of the mobile web app assets folder, which is located under the build folder.

EmailComposerPlugin.open({
  attachments: [{
    type: 'asset',
    path: '/icon/favicon.png' // starting slash is important
  }]
})

Base64

The code below shows how to attach a base64 encoded image which will be added as an image. You must set a name.

EmailComposerPlugin.open({
  attachments: [{
    type: 'base64',
    path: 'iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6...',
    name: 'icon.png' // this is required
  }]
})

API

hasAccount()

hasAccount() => Promise<{ hasAccount: boolean; }>

Checks if the User can send a Mail iOS: Check if the current Device is configured to send mail Android: Currently does nothing

Returns: Promise<{ hasAccount: boolean; }>


open(...)

open(options?: OpenOptions | undefined) => Promise<void>

Open the E-Mail Composer

Param Type Description
options OpenOptions optional Options to prefill the E-Mail

Interfaces

OpenOptions

Prop Type Description
to string[] email addresses for TO field
cc string[] email addresses for CC field
bcc string[] email addresses for BCC field
subject string subject of the email
body string email body
isHtml boolean indicates if the body is HTML or plain text (primarily iOS)
attachments Attachment[] attachments that are added to the mail file paths or base64 data streams

Attachment

Prop Type Description
path string The path of the attachment. See the docs for explained informations.
type 'absolute' | 'resource' | 'asset' | 'base64' The type of the attachment. See the docs for explained informations.
name string The name of the attachment. See the docs for explained informations. Required for base64 attachements.

Changelog

The full Changelog is available here

About

E-Mail Composer Plugin for Capacitor

License:MIT License


Languages

Language:Java 46.7%Language:Swift 27.0%Language:JavaScript 11.9%Language:TypeScript 7.7%Language:Ruby 3.8%Language:Objective-C 2.9%