开发者

Can I use HTML5 to send a client-side email?

开发者 https://www.devze.com 2023-02-20 05:22 出处:网络
I want to send an email in HTML5. I don\'t want to force the user to open a mail cli开发者_如何学编程ent, I want to send the email directly from the web page.

I want to send an email in HTML5. I don't want to force the user to open a mail cli开发者_如何学编程ent, I want to send the email directly from the web page.

On a side note, is there any way at all to do this in JavaScript? I know it's probably not possible, just wondering if there are any crafty ways to pull it off going completely through the client.


In short NO not directly from the client (excluding hacks).

you could make an ajax call to your server and send an email.

the problem with doing it from the client and not using a mail client is complicated. For example most consumer ISPs have their own SMTP relay that all outbound mail on port 25 must be transmitted over. You website will have trouble obtaining the proper information to do this. Secondly the webbrowser doesn't understand the SMTP protocol and neither does the XMLHttpRequest object.

So if you are a hacker ninja, maybe you can figure something out with ActiveX, Java Applets, or flash, but you basically would have to be operating directly with a tcp socket and issuing SMTP protocol commands over that socket.

There are many obstacles to overcome, in fact I don't know how to do it, but where there is will there is a way. Don't be surprised that if you do find a hack, it may be plugged swiftly by the major browser vendors.


Yes it is possible. But not practical ** See Edit 2

Some HTML5 implementations include support for websockets, essentially a tcp connection to a server. Overlay some send/recv code and you can build a SMTP client.

In fact it looks like nodejs and websocket support has been used to implement a smtp client ... see here ...

You would still need a smtp server, username, password, etc just like a standard smtp client in order for it to work.

Using this method for spam would be unlikely as your smtp provider could easily cancel your account.

=== EDIT ===

Actually you could build a server less version, it would have to also implement name server lookups to find mx records. Chances are however that any decent SMTP servers maintain spamlist blacklist tables and connecting from an random ip address would see the email commonly marked as spam.

Also talking to smtp servers that require secure mail connections could be difficult.

As others have mentioned there are malicious uses to this implementation like sending spam. I guess it is possible you could be a HTML5 botnet creator but I would have thought that you would know most of this already :)

=== EDIT 2 ===

As Mark At Ramp51 mentioned, Handshaking is required with websockets. This was something I wasn't aware of. You would have to hack the websocket implementation to bypass handshaking.

The correct way is to have the web server forward the email.


This is not possible.

Instead, you should use AJAX to send the email on the server.


You can't send the email using JavaScript alone. You'll need some form of server side processing (PHP, ASP, etc) to send the actual email.

There's a good tutorial on setting up an ajax form here: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

It doesn't include the PHP (or ASP, etc) for sending the email, but there are plenty of tutorials out there for how to send an email using PHP.


Send email directly from Javascript

From official resource:

How does it work?

  1. Connect your email service Choose from a wide variety of email services. We support both transactional email services (Mailgun, Mailjet, Mandrill, SendGrid, Amazon SES and Postmark) and personal email services (AOL, Gmail, FastMail, iCloud, Mail.ru, Outlook, Yahoo, Yandex and Zoho).

  2. Create email templates Choose from a list of our template designs, or easily build your own. Templates are parametrized, so that you can further customize them via Javascript.

  3. Send email with our Javascript API Add our Javscript SDK, and start sending emails!

Here's what a typical call looks like:

var service_id = 'my_mandrill';
var template_id = 'feedback';
var template_params = {
  name: 'John',
  reply_email: 'john@doe.com',
  message: 'This is awesome!'
};

emailjs.send(service_id,template_id,template_params);

All existing APIs require using a secret key, which you obviously wouldn't want to share in your front-end code. Specified service overcome this by allowing sending only predefined templates, so for a "Share with a friend" feature you'd create a template called "share".


You can't do it purely through client side code.

You can do it with a server callback, AJAX.

0

精彩评论

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