开发者

Mail through Javascript

开发者 https://www.devze.com 2023-01-15 23:16 出处:网络
How can we send m开发者_开发技巧ail using JavaScript? 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

How can we send m开发者_开发技巧ail using JavaScript?


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 = "bob@someplace.com" },
    success: function(data, status) {
       alert("Mail sent");
    },
    error: function() {
       alert("Mail failed.");
    }
});


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!


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消