简体   繁体   中英

How to execute mailto without any click in javascript?

I want to send a email from javascript without clicking on anything.

I want to have something like this:

<script>var x="mailto:xyz@xyz.com";</script>

And then without any user input send out the mail. Looking for native javascript solution and not any framework based.

Can't--And thank goodness for that, I don't want to visit a website that can send email out on my behalf without me knowing about it .

Besides that, all JavaScript can do is launch a "compose" (tell whatever email application that's installed on the client that they'd like to send out an email). The agent itself can't send email as that would need to be done by an application on the client or on the server itself.

You may be able to do something like:

window.location = 'mailto:john.smith@example.com';

But all that would do is compose a new email directed at john.smith@example.com then it's up to the visitor to continue.

You absolutely can, but not the way you think you can. You can't do it from the client. That would require a click (which you can't fake--DOM events cannot be triggered by the client). But... you CAN do it on the server, provided you actually control the server. Basically you do it through an AJAX request that's triggered on the UI, which sends a request to the server. The server does the actual sending of email. The server code would depend heavily on your technology stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM