How can we send mail using JavaScript?
4 Answers
It's not possible directly. You'll have to use a server side language, such as ASP.Net, and call a server side email method using AJAX. Here's a quick example using jQuery:
$.ajax({
url: "MyController/SendMail",
data: { recipient = "[email protected]" },
success: function(data, status) {
alert("Mail sent");
},
error: function() {
alert("Mail failed.");
}
});
Comments
1 Comment
Like said before, it's not possible with Javascript alone. Even the HTML5 Websocket API won't help.
However, it's not necessary to implement a server bridge. There's a common workaround using a Flash/SWF as bridge, which can open real socket connections. In theory this allows full client-side smtp connections. Though, I'm sure nobody has yet done that, nor would it seem feasible for you.