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

问题描述 投票:0回答:4
reactjs react-redux react-router redux-form mailto
4个回答
20
投票

您可以使用

mailto
 打开 
window

链接
window.open('mailto:[email protected]?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="[email protected]" subject="Hello & Welcome" body="Hello world!">
    Mail me!
  </Mailto>,
  document.getElementById('root')
);

参考链接


0
投票
const openEmail = () => {
  const recipient = "[email protected]";
  const subject = encodeURIComponent("Subject Here");
  const body = encodeURIComponent("Body content goes here.");

  // Check if default email client exists (mailto)
  try {
    window.location.href = `mailto:${recipient}?subject=${subject}&body=${body}`;
  } catch (e) {
    // Fallback to Outlook Web App
    window.open(
      `https://outlook.office.com/mail/deeplink/compose?to=${recipient}&subject=${subject}&body=${body}`,
      '_blank'
    );
  }
};

-3
投票

您必须导入此“链接”

<Button onPress={() => Linking.openURL('mailto:[email protected]?subject=SendMail&body=Description') }
              title="[email protected]" />
© www.soinside.com 2019 - 2024. All rights reserved.