首页指南参考教程

Expo MailComposer iconExpo MailComposer

GitHub

npm

一个库,提供使用系统特定 UI 撰写和发送电子邮件的功能。

Android
Web

expo-mail-composer 允许你使用操作系统 UI 快速轻松地撰写和发送电子邮件。该模块无法在 iOS 模拟器上使用,因为你无法登录其中的邮件账户。

¥**expo-mail-composer** allows you to compose and send emails quickly and easily using the OS UI. This module can't be used on iOS Simulators since you can't sign into a mail account on them.

安装

¥Installation

Terminal
npx expo install expo-mail-composer

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

API

import * as MailComposer from 'expo-mail-composer';

Methods

MailComposer.composeAsync(options)

NameTypeDescription
optionsMailComposerOptions-

Opens a mail modal for iOS and a mail app intent for Android and fills the fields with provided data. On iOS you will need to be signed into the Mail app.

Returns

  • Promise<MailComposerResult>

A promise fulfilled with an object containing a status field that specifies whether an email was sent, saved, or cancelled. Android does not provide this info, so the status is always set as if the email were sent.

MailComposer.isAvailableAsync()

Determine if the MailComposer API can be used in this app.

Returns

  • Promise<boolean>

A promise resolves to true if the API can be used, and false otherwise.

  • Returns true on iOS when the device has a default email setup for sending mail.
  • Can return false on iOS if an MDM profile is setup to block outgoing mail. If this is the case, you may want to use the Linking API instead.
  • Always returns true in the browser and on Android.

Types

MailComposerOptions

A map defining the data to fill the mail.

NameTypeDescription
attachments
(optional)
string[]

An array of app's internal file URIs to attach.

bccRecipients
(optional)
string[]

An array of e-mail addresses of the BCC recipients.

body
(optional)
string

Body of the e-mail.

ccRecipients
(optional)
string[]

An array of e-mail addresses of the CC recipients.

isHtml
(optional)
boolean

Whether the body contains HTML tags so it could be formatted properly. Not working perfectly on Android.

recipients
(optional)
string[]

An array of e-mail addresses of the recipients.

subject
(optional)
string

Subject of the e-mail.

MailComposerResult

NameTypeDescription
statusMailComposerStatus-

Enums

MailComposerStatus

MailComposerStatus Values

CANCELLED

MailComposerStatus.CANCELLED = "cancelled"

SAVED

MailComposerStatus.SAVED = "saved"

SENT

MailComposerStatus.SENT = "sent"

UNDETERMINED

MailComposerStatus.UNDETERMINED = "undetermined"
Expo 中文网 - 粤ICP备13048890号