如何在React Native中以电子邮件形式发送表单内容



对于react,已经有了像EmailJs这样的方法,但我不知道有任何服务可以从表单中获取内容并在react Native中作为电子邮件发送。有人能提供一些建议来帮助解决这个问题吗谢谢

创建一个接收输入的函数,将其重新转换为电子邮件内容,并将您重定向到gmail以发送。。从npm 安装qs

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);
}
//then import the above function and use it as
 sendEmail(
                'destinationemail@gmail.com',
                your emailsubject,
                your emailmessage,
                { cc: 'test@gmail.com; test2@gmail.com;' }
            ).then(() => {
                console.log('Your message was successfully sent!');
            });

最新更新