Search code examples
javascripthtmlmailto

How to open an email automatically on the page load


I'd like to open an email automatically with To & subject, when the html page loads. I need to use only mailto functionality. Can someone help me how to do this?


Solution

  • Redirect the user to a mailto link. This can be done with basic JavaScript:

    location.href = "mailto:[email protected]?subject=Test+Message";
    

    Just take into consideration the fact that:

    1. A lot of people use online email these days (GMail, hotmail, etc) - not me personally, but... other people.
    2. If the user has a desktop email program, you'll be forcing an unexpected window open on them.
    3. It's even worse if the user has a desktop email program, but has never set it up - as would be the case of most of the people in point 1. The window would open and then the whole "email setup" process would start.

    Just be careful.