最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - sending email from html using javascript without default outlook - Stack Overflow

programmeradmin4浏览0评论

I want to send an email using javascript without using the outlook. I don't want to use mailto object which use outlook for sending email.

Is there any direct method provided by JavaScript to send the data submitted in the form to an email address.

I want to send an email using javascript without using the outlook. I don't want to use mailto object which use outlook for sending email.

Is there any direct method provided by JavaScript to send the data submitted in the form to an email address.

Share Improve this question asked Oct 4, 2011 at 12:32 JohnJohn 7143 gold badges12 silver badges31 bronze badges 2
  • 3 "mailto" doesn't use Outlook, it uses whichever email program is the user's default (which, OK, might be Outlook). – nnnnnn Commented Oct 4, 2011 at 12:35
  • You need something on the back end to handle sending the actual mail, which would depend on what the site is sitting on top of: php, asp, etc. – Doozer Blake Commented Oct 4, 2011 at 12:36
Add a ment  | 

7 Answers 7

Reset to default 5

Kinda. At least, you have the possibility to do the following:

Via JavaScript, you can make a call to a server-based service which can dispatch an e-mail via SMTP. Whether this call is made via a simple form submission to your own server or via an XmlHttpRequest to a remote service is only a matter of a) whether you will implement it yourself and b) whether you're able to find a service elsewhere.

tl;dr:

  • JavaScript itself cannot dispatch e-mails
  • However, you can make JavaScript call a service which is able to "talk" SMTP.

It will be some work, but I think with Websockets you can get this to work.

You would then need to implement the SMTP protocol yourself:

http://www.smtp2go./articles/smtp-protocol.html

Here is a tutorial on websockets:

http://net.tutsplus./tutorials/javascript-ajax/start-using-html5-websockets-today/

You may want to read through the websockets spec for more details:

http://dev.w3/html5/websockets/#the-websocket-interface

So, in theory you should be able to do this, but according to the specification SMTP is generally blocked from Websockets:

If port is a port to which the user agent is configured to block access, then throw a SecurityError exception. (User agents typically block access to well-known ports like SMTP.)

But, this is typically blocked, not always, or required, so it could possibly work, and is the only way I can see for javascript to send emails.

No.

Such a feature would be a security risk as it could be easily abused by spammers. To directly send an e-mail without opening up an instance of the user's default e-mail client, you have to pass the data to a server that will send the e-mail.

I think you should write a backend program which accept a email address and email content, then send the email. Then you can submit the form to the backend with Ajax in the browser.

I really hope there is no way to do this with client-side code, because I really don't want some random webpage using my PC to send emails without me knowing it.

And having said that, I'm sure the answer is "no" anyway.

The whole point of "mailto" is that it opens the user's default email program (not necessarily Outlook) so that they know they're sending an email and can edit all fields before continuing (assuming they want to continue at all).

The closest you can get that I can think of is for your JavaScript to make an Ajax call to your webserver and then send the email from your server-side code.

The mail program opened depends on what the default is set to on the individual client machine.

To send an e-mail without touching an e-mail program such as Outlook, Thunderbird etc then you need to use some kind of server-side language such as PHP and it is very easy to do aswell and there are plenty of resources out there so that you can achieve what you want to.

NO! JavaScript can’t email a form! but, there are alternatives to send the form data to an email address.

There is no direct method provided by JavaScript to send the data submitted in the form to an email address.

The main concern for not providing a ‘JavaScript email form’ feature is security. Suppose there is a feature in JavaScript to send email. Some malicious coder can write a script to send email to some address immediately when you visit their page. This will reveal your email address to some third party without your knowledge. They will start filling your mail box with lots of spam messages!

发布评论

评论列表(0)

  1. 暂无评论