Keerthi
Keerthi

Reputation: 51

on click of a button how can I re-direct to the outlook mail with automatic body and sender using Reactjs?

sendEmail = () => {
  window.open("mailto:[email protected]?subject=SendMail&body=Description");
};

return (
  <div className="App">
    <button
      type="button"
      className="btn btn-danger"
      onClick={this.sendEmail}
    >
      Send email
    </button>
  </div>
);

I wrote my code in ReactJs but I am getting the blank screen. Please help.

Upvotes: 1

Views: 7079

Answers (1)

Niklas Rydkvist
Niklas Rydkvist

Reputation: 683

I don't know why this doesn't work for you, I tested it and it works fine for me, but try using an anchor link instead, like this:

mailtoHref = "mailto:[email protected]?subject=SendMail&body=Description";

return (
  <div className="App">
    <a href={this.mailtoHref} className="btn btn-danger">
      Send email
    </a>
  </div>
);

Upvotes: 1

Related Questions