Mail

The Mail module allows you to present a mail compose view within your app. You can specify recipients, subject, body, and attachments.

Availability Check

1Mail.isAvailable: boolean
  • Description: Indicates whether the device supports sending emails.
  • Returns: true if available, false if not

Example

1if (Mail.isAvailable) {
2  console.log('Mail service is available')
3} else {
4  console.log('Mail service is not available')
5}

Method: Mail.present

1Mail.present(options: MailOptions): Promise<void>

Parameters: options (required)

Defines the email content and attachments. The following fields are supported:

Field Type Required Description
toRecipients string[] Yes Array of recipient email addresses
ccRecipients string[] No Array of CC (carbon copy) email addresses
bccRecipients string[] No Array of BCC (blind carbon copy) email addresses
preferredSendingEmailAddress string No Preferred sender email address
subject string No Email subject
body string No Email body content
attachments Attachment[] No List of attachments

Attachment Structure

Each attachment should include the following fields:

Field Type Description
data Data The file data to attach
mimeType string The MIME type of the attachment (e.g., image/png, application/pdf)
fileName string The file name of the attachment (e.g., photo.png)

Return Value

  • Returns a Promise<void>
  • Resolves when the mail compose view is presented and dismissed
  • Does not indicate whether the email was sent successfully (handled by the system)

Usage Examples

Basic Example: Send an Email

1if (Mail.isAvailable) {
2  await Mail.present({
3    toRecipients: ['example@example.com'],
4    subject: 'Hello',
5    body: 'This is a test email sent from the app'
6  })
7}

Example with CC and BCC

1await Mail.present({
2  toRecipients: ['recipient1@example.com'],
3  ccRecipients: ['cc1@example.com', 'cc2@example.com'],
4  bccRecipients: ['bcc@example.com'],
5  subject: 'Meeting Reminder',
6  body: 'Please find the meeting details below'
7})

Example with Attachment

1const imageData = await FileManager.readAsData('/path/to/photo.png') // Assume this returns Data type
2
3await Mail.present({
4  toRecipients: ['user@example.com'],
5  subject: 'Check the Attachment',
6  body: 'Please see the attached image',
7  attachments: [
8    {
9      data: imageData,
10      mimeType: 'image/png',
11      fileName: 'photo.png'
12    }
13  ]
14})

Notes

  • Always check Mail.isAvailable before calling Mail.present to avoid runtime errors.
  • The actual sending of the email is handled by the system mail app. This API only presents the compose view.
  • Supports multiple attachments. Make sure to provide the correct MIME type for each file.

Reference