如何启动和打开电子邮件客户端ReactJS

问题描述

我想在我的react应用程序中显示一个类似click here的弹出窗口。简而言之,我要在 ReactJs 中启动并打开电子邮件客户端。我目前正在使用一个简单的p标签

 <p className="cnct_email_addr">Email US</p>

我知道有这样一种使用mailto的方法

<a href="mailto:[email protected]">Email Us</a>

但是我想知道是否还有更反应的方法。如果有的话,请告诉我。

解决方法

const Mailto = ({ email,subject,body,children }) => {
  return (
    <a href={`mailto:${email}?subject=${encodeURIComponent(subject) || ''}&body=${encodeURIComponent(body) || ''}`}>{children}</a>
  );
};

ReactDOM.render(
  <Mailto email="[email protected]" subject="Hello & Welcome" body="Hello world!">
    Mail me!
  </Mailto>,document.getElementById('root')
);

参考link

,

您可以使用mailto打开window链接

window.open('mailto:[email protected]?subject=Subject&body=Body%20goes%20here')
,

您必须导入此“链接”

<Button onPress={() => Linking.openURL('mailto:[email protected]?subject=SendMail&body=Description') }
              title="[email protected]" />