How to send email from JavaScript HTML using mailto


Here is a simple example to send an email using JavaScript - mailto. You can use this code with any control (example - button) and even any event (example - onclick).

This code will invoke the user's default email client with the required parameters pre-filled (like email address, subject, message body) and user just needs to click send in order to send the email.

Note - It is not possible to directly send email from JavaScript, you can only invoke/open the default email client.

Code Type: Specify only Email ID
window.open('mailto:useremail@domain.com');
Code Type : Specify multiple Email ID (separate id's by comma(,) or semi-colon(;) )
window.open('mailto:useremail1@domain.com,useremail2@domain.com');
Code Type: Specify Email ID, Subject, Body
window.open('mailto:useremail@domain.com?subject=This is the email subject&body=This is the email body');





Recent Posts:
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.