-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (27 loc) 路 779 Bytes
/
Copy pathindex.js
File metadata and controls
36 lines (27 loc) 路 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Linking } from 'react-native'
import qs from 'qs'
async function sendEmail (to, { cc, bcc, subject, body, checkCanOpen = true } = {}) {
let url = 'mailto:'
if (to) {
const toStr = Array.isArray(to) ? to.join(',') : to
url += encodeURIComponent(toStr)
if (cc) {
cc = Array.isArray(cc) ? cc.join(',') : cc
}
if (bcc) {
bcc = Array.isArray(bcc) ? bcc.join(',') : bcc
}
const query = qs.stringify({ cc, bcc, subject, body })
if (query.length) {
url += `?${query}`
}
}
if (checkCanOpen) {
const supported = await Linking.canOpenURL(url)
if (!supported) {
return Promise.reject(new Error('Provided URL can not be handled'))
}
}
return Linking.openURL(url)
}
export default sendEmail