HTML CSS Javascript jQuery AJAX PHP Java MORE
Need a Website Or Web Application.Contact : +91 9437911966 (Whatsapp) Note: Paid Service

How to send an email from JavaScript

<script src="https://smtpjs.com/v3/smtp.js"></script>

index.html

<!DOCTYPE html> 
<html> 

<head> 
<title>Send Mail</title> 
<script src= 
	"https://smtpjs.com/v3/smtp.js"> 
</script> 

<script type="text/javascript"> 
	function sendEmail() { 
	Email.send({ 
		Host: "smtp.gmail.com", 
		Username: "[email protected]_address.com", 
		Password: "Enter your password", 
		To: '[email protected]_address.com', 
		From: "[email protected]_address.com", 
		Subject: "Sending Email using javascript", 
		Body: "Well that was easy!!", 
	}) 
		.then(function (message) { 
		alert("mail sent successfully") 
		}); 
	} 
</script> 
</head> 

<body> 
<form method="post"> 
	<input type="button" value="Send Email"
		onclick="sendEmail()" /> 
</form> 
</body> 

</html> 

what if you have multiple receivers. In that case you have to do nothing just configure your sendMail() function as

Rest all we be same. If you want to send html formatted text to the receiver

html: "<h1>GeeksforGeeks</h1>
<p>A computer science portal</p>"

in order to send attachment just write the following code in sendMail() function:

Attachments : [{
    name : "File_Name_with_Extension",
    path:"Full Path of the file"
}]

index.html

<!DOCTYPE html> 
<html> 

<head> 
<title>Sending Mail</title> 
<script src="https://smtpjs.com/v3/smtp.js"></script> 
<script type="text/javascript"> 
	function sendEmail() { 
	Email.send({ 
		Host: "smtp.gmail.com", 
		Username: "[email protected]_address.com", 
		Password: "Enter your password", 
		To: '[email protected]_address.com', 
		From: "[email protected]_address.com", 
		Subject: "Sending Email using javascript", 
		Body: "Well that was easy!!", 
		Attachments: [ 
		{ 
			name: "File_Name_with_Extension", 
			path: "Full Path of the file" 
		}] 
	}) 
		.then(function (message) { 
		alert("Mail has been sent successfully") 
		}); 
	} 
</script> 
</head> 

<body> 
<form method="post"> 
	<input type="button" value="Send Mail"
		onclick="sendMail()" /> 
</form> 
</body> 

</html>