Justin808
Justin808

Reputation: 21522

Sending an email from the browser with javascript and flash... is it possible?

I'm wondering if its possible to do what I'm thinking, and if it is possible, does anyone know of a flash object that does what I need?

I know a Flash object can provide a javascript API to interact with it, what I dont know is can Flash send an email directly without the need to talk to the webserver to do so? If thats possible would it not be possible to write a flash object that did nothing but provide an API to send emails? Has such a thing been created that is out there for others to use?

I'm looking to create a email form on a web page but the site is static (no server scripting). In my situation server scripting is not possible as there is no server, the site is 100% client side on a CD/DVD/USB Stick.

Upvotes: 0

Views: 705

Answers (4)

Rob Fox
Rob Fox

Reputation: 5571

No, flash nor JS can do this alone as they are client-side technologies. You need to create a server side script to send the email and then request it from your client.

It doesn't matter if the swf file is on a USB stick or wherever, you can still connect to a server. Most web hosts support php so that would probably be the easiest way. Check out this Google search.

EDIT: if you can't use a server then you could use a mailto link, this opens the users default email client.

var mailto:String = "mailto:[email protected]";
navigateToURL(new URLRequest(mailto), "_blank");

You can also add a subject and body. See http://www.ianr.unl.edu/internet/mailto.html for the syntax.

Upvotes: 3

gravitystorm
gravitystorm

Reputation: 933

Yes, this is possible using flash, although I have not done so myself and I wouldn't advise it. The general strategy would be to connect to a specific mailserver using sockets.

  1. The server would need a "Socket Policy File" available on port 843. See http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html for more. It would give permissions for connecting to the chosen port for the mail relay (e.g. 25).
  2. You can then use the flash Socket library in order to, in effect, create a telnet client. See http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf7.html
  3. Construct your email as a payload for the socket, and send it. See http://www.yuki-onna.co.uk/email/smtp.html

Of course, if you are distributing these CDs to the entire world, your mail server socket policy would have to accept connections from anyone on any machine, you'd be running an open mail relay, chaos would ensue, dogs and cats living together...

Now it's unlikely that you'll find a public SMTP server that lets you do this, and if you really don't have access to anything server-side whatsoever (no webserver, no control over any SMTP server) then you'll need to rely on the client-side mailto: links instead.

Upvotes: 1

Fabian
Fabian

Reputation: 4348

You can not send an email if there's no internet connection, doesn't matter if you use JavaScript, Flash or anything else.

Edit: http://code.google.com/p/smtpmailer/ This is written in ActionScript and might fit your needs.

http://flashflex.com/sending-mail-in-actionscript-using-smtp/ This is some background information.

Upvotes: 0

orip
orip

Reputation: 75447

Since it runs off of a CD in the user's computer and you have no server, your best (only?) option would be to run the user's own mail client.

Try creating a mailto link dynamically with JavaScript and then clicking it. It should run the local mail client (Outlook, Thunderbird, etc.) with the input you specify. The users would have to click "send" themselves.

Upvotes: 0

Related Questions