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

10
我想在我的React应用程序中展示一个弹出框,类似于这里。简单来说,我想在ReactJs中启动和打开电子邮件客户端。目前我正在使用一个简单的p标签:
 <p className="cnct_email_addr">Email US</p>

我知道可以像这样使用mailto:

<a href="mailto:someone@yoursite.com">Email Us</a>

但我想知道是否有更符合React方式的方法。如果有,请告诉我。

3个回答

19

您可以使用 window 打开 mailto 链接

window.open('mailto:email@example.com?subject=Subject&body=Body%20goes%20here')

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

ReactDOM.render(
  <Mailto email="foo@bar.baz" subject="Hello & Welcome" body="Hello world!">
    Mail me!
  </Mailto>,
  document.getElementById('root')
);

参考链接


-3

你必须导入这个“Linking”

<Button onPress={() => Linking.openURL('mailto:support@example.com?subject=SendMail&body=Description') }
              title="support@example.com" />

3
这是针对React Native的。它只适用于移动应用程序。我需要它用于ReactJs的Web应用程序。 - K.SINGH

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接