簡體   English   中英

如何在 React Native 中將表單內容作為電子郵件發送?

[英]How to send the content of a form as email in React Native?

有了 React,就有了像 EmailJs 這樣的方法,但我不知道有任何服務可以從表單中獲取內容並在 React Native 中將其作為電子郵件發送。 誰能提供一些指針來幫助解決這個問題謝謝

創建一個接收輸入的函數,將其重塑為電子郵件內容,並將您重定向到 gmail,僅用於從 npm 發送..install 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!');
            });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM