Skip to content

Instantly share code, notes, and snippets.

@m-tymchyk
Created October 19, 2018 13:40
Show Gist options
  • Save m-tymchyk/ea71bfdf9b60af0205a16165d3cc4d3f to your computer and use it in GitHub Desktop.
Save m-tymchyk/ea71bfdf9b60af0205a16165d3cc4d3f to your computer and use it in GitHub Desktop.
React Native / How to send email
// send-email.js
// We can use react-native Linking to send email
import qs from 'qs';
import { Linking } from 'react-native';
export async function sendEmail(to, subject, body, options = {}) {
const { cc, bcc } = options;
let url = `mailto:${to}`;
// Create email link query
const query = qs.stringify({
subject: subject,
body: body,
cc: cc,
bcc: bcc
});
if (query.length) {
url += `?${query}`;
}
// check if we can use this link
const canOpen = await Linking.canOpenURL(url);
if (!canOpen) {
throw new Error('Provided URL can not be handled');
}
return Linking.openURL(url);
}
// example.js
import { sendEmail } from './send-email';
sendEmail(
'[email protected]',
'Greeting!',
'I think you are fucked up how many letters you get.'
).then(() => {
console.log('Our email successful provided to device mail ');
});
@ProgrammerNephi
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment