user3259472
user3259472

Reputation:

ReactJS + Redux: How to trigger a button to open up a Mac Mail/Windows Mail with property email?

I have a button and a string property that holds an email address. Once the button is clicked, I want it to open up the Mac Mail/Windows Mail with the string property's email address inside the To:

How can I go about doing so? Any guidance or insight would be greatly appreciated!

Upvotes: 3

Views: 7604

Answers (1)

Kokovin Vladislav
Kokovin Vladislav

Reputation: 10391

you can use window.location.href = `mailto:${this.props.email}`

class EmailButton extends Component {
    constructor(props){
        super(props);
        this.onClick = this.onClick.bind(this);
    }
    onClick(){
        window.location.href = `mailto:${this.props.email}`;
    }
    render(){
        return <button onClick={this.onClick}>EmailButton</button>;
    }
}

webpackbin demo

also you can use <a href={`mailto:${email}`}>EmailButton</a>

Upvotes: 10

Related Questions