1.16.0 • Published 24 days ago

react-native-email-link v1.16.0

Weekly downloads
24,651
License
MIT
Repository
github
Last release
24 days ago

React Native Email Link

GitHub release NPM GitHub license


An easy way to open an email app of the user's choice, based on the apps they have installed on their device. Very helpful for magic link logins.

Currently supported apps:

  • Apple Mail
  • Gmail
  • Inbox
  • Spark
  • Airmail
  • Outlook
  • Yahoo Mail
  • Superhuman
  • Yandex
  • ProtonMail
  • Fastmail

Installation

1. Install the package

yarn add react-native-email-link

This package works with autolinking on RN>=0.60. If you're using an earlier version of React Native, please install version 1.4.0 of the library, or check out the legacy rnpm branch.

2. Post-install steps

Based on the platforms your app supports, you also need to:

To allow your app to detect if any of the mailbox apps are installed, an extra step is required on iOS. Your app needs to provide the LSApplicationQueriesSchemes key inside ios/{my-project}/Info.plist to specify the URL schemes with which the app can interact.

Just add this in your Info.plist depending on which apps you'd like to support. Omitting these might mean that the library can't detect some of the maps apps installed by the user.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mailto</string>
    <string>message</string>
    <string>readdle-spark</string>
    <string>airmail</string>
    <string>ms-outlook</string>
    <string>googlegmail</string>
    <string>inbox-gmail</string>
    <string>ymail</string>
    <string>superhuman</string>
    <string>yandexmail</string>
    <string>fastmail</string>
    <string>protonmail</string>
    <string>szn-email</string>
</array>

To allow the library to work with Expo you need to enable the config plugin. This plugin will automatically configure your Expo application with the correct settings for this library to function.

To enable the config plugin, add it to the plugins array inside your app.config.js/app.config.json. For example:

{
  "name": "my app",
  "plugins": ["react-native-email-link"]
}

Want this library to work on Android too? Because the library uses native code on Android you need to follow Expo's guide for custom native code.

Usage

openInbox

import { openInbox } from "react-native-email-link";

openInbox();

Arguments

title

Text for the top of the ActionSheet or Intent.

TypeRequiredDefault
stringNo'Open mail app'

message

Subtext under the title on the ActionSheet

TypeRequiredDefaultPlatform
stringNo'Which app would you like to open?'iOS

cancelLabel

Text for last button of the ActionSheet.

TypeRequiredDefaultPlatform
stringNo'Cancel'iOS

removeText

If true, not text will be show above the ActionSheet or Intent. Default value is false.

TypeRequiredDefault
booleanNofalse

defaultEmailLabel

Text for first button of the ActionSheet.

TypeRequiredDefaultPlatform
stringNo'Default email reader'iOS

newTask

If true, the email Intent will be started in a new Android task. Else, the Intent will be launched in the current task.

Read more about Android tasks here.

TypeRequiredDefaultPlatform
booleanNotrueAndroid

Example

import { openInbox } from "react-native-email-link";

openInbox({
  message: "Whatcha wanna do?",
  cancelLabel: "Go back!",
});

openComposer

import { openComposer } from "react-native-email-link";

openComposer();

Arguments

app

App to open the composer with

TypeRequiredExample
stringNoAn app's id that can be retrieved with getEmailClients
On Android - id holds the package name, e.g. com.mail.app
On iOS - id holds the app slug/name, e.g. gmail

title

Text for the top of the ActionSheet or Intent.

TypeRequiredDefault
stringNo'Open mail app'

message

Subtext under the title on the ActionSheet.

TypeRequiredDefaultPlatform
stringNo'Which app would you like to open?'iOS

cancelLabel

Text for last button of the ActionSheet.

TypeRequiredDefaultPlatform
stringNo'Cancel'iOS

removeText

If true, not text will be show above the ActionSheet or Intent. Default value is false.

TypeRequiredDefault
booleanNofalse

defaultEmailLabel

Text for first button of the ActionSheet.

TypeRequiredDefaultPlatform
stringNo'Default email reader'iOS

to

Recipient's email address.

TypeRequiredDefault
stringNonull

cc

Email's cc.

TypeRequiredDefault
stringNonull

bcc

Email's bcc.

TypeRequiredDefault
stringNonull

subject

Email's subject.

TypeRequiredDefault
stringNonull

body

Email's body.

TypeRequiredDefault
stringNonull

encodeBody

Apply encodeURIComponent to the email's body.

TypeRequiredDefault
booleanNofalse

Example

import { openComposer } from "react-native-email-link";

openComposer({
  to: "support@example.com",
  subject: "I have a question",
  body: "Hi, can you help me with...",
});

getEmailClients

import { getEmailClients } from "react-native-email-link";

const clients = await getEmailClients();

console.log(clients)[
  {
    iOSAppName: "gmail", // iOS only
    prefix: "gmail://",
    title: "GMail",
    androidPackagename: "com.google.android.gm", // Android only
    id: "gmail", // depending on the platform, holds either the package name or the app slug value
  }
];

To utilize this feature to display an email client picker within a custom UI and subsequently use the openComposer to launch a specific app, you just need to pass the id (from response) value into the options (options.app) within the openComposer.


1.16.0

24 days ago

1.15.0

3 months ago

1.14.8

6 months ago

1.14.7

8 months ago

1.14.6

10 months ago

1.14.5

1 year ago

1.14.4

1 year ago

1.14.3

1 year ago

1.14.2

1 year ago

1.14.1

2 years ago

1.14.0

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.11.4

3 years ago

1.12.2

3 years ago

1.12.1

3 years ago

1.12.0

3 years ago

1.11.3

3 years ago

1.11.2

3 years ago

1.11.1

3 years ago

1.11.0

3 years ago

1.10.1

3 years ago

1.10.0

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.4

4 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago