1

How can we send mail using JavaScript?

2
  • 2
    You can't do that with pure JS. Commented Sep 11, 2010 at 6:43
  • in anycase you need SMTP Commented Sep 11, 2010 at 7:43

4 Answers 4

2

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.");
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

It's possible, from client-interfacing JS, to send an XMLHttpRequest request to a URI that understands how to send mail that corresponds to a given payload -- you will need to listen for those asynchronous HTTP request server side using some kind of server side language, though!

Comments

0

That is not possible, you need some server-side programming language such as PHP, ASP, Python, etc.

1 Comment

i am using php . so pls guide with reference to php
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.