views:

3658

answers:

6

Hello, I want to create a client side mail creator web page. I know the problems of using the mailto action in an html form (not standard, no default mail appication set on the client...). but the web page isn't very important, and they don't care very much.

The mail created by the mailto action has the syntax:

subject: undefined subject
body:

param1=value1
param2=value2
.
.
.
paramn=valuen

¿Can i use javascript to format the mail like this?

Subject:XXXXX

Body: Value1;Value2;Value3...ValueN

Thanks

PD: sry for my bad english

A: 

Is there a reason you can't just send the data to a page which handles sending the mail? It is pretty easy to send an email in most languages, so unless there's a strong reason to push it to client side, I would recommend that route.

Mike Stone
+2  A: 

You more or less only have two alternatives when sending mail via the browser..

  1. make a page that takes user input, and allows them to send the mail via your web-server. You need some kind of server-side scripting for this.
  2. use a mailto: link to trigger opening of the users registered mail client. This has the obvious pitfalls you mentioned, and is less flexible. It needs less work though.
Lars Mæhlum
+1  A: 

With javascript alone, it's not possible.
Javascript is not intended to do such things and is severely crippled in the way it can interact with anything other than the webbrowser it lives in, (for good reason!).

Think about it: a spammer writing a website with client side javascript which will automatically mail to thousands of random email addresses. If people should go to that site they would all be participating in a distributed mass mailing scam, with their own computer... no infection or user interaction needed!

Sven
A: 

I don't want to use server-side options becase i don't have a server side, i have a desktop java application which connects to mail server using JavaMail API, if i can't use javascript to format the mail like i want, i will change the mail parser to accept this mail format.

Thx by the answers

Telcontar
+2  A: 

What we used in a projet is a popup window that opens a mailto: link, it is the only way we found to compose a mail within the default mail client that works with all mail clients (at least all our clients used).

var addresses = [...];
var href = "mailto:" + addresses.splice(0, 1) + "?"
         + "cc=" + addresses.join(",") + "&"
         + "subject=" + subject + "&"
         + "body=" + body;
var wndMail = window.open(href, "_blank", "scrollbars=yes,resizable=yes,width=10,height=10");
if( wndMail )
{
    wndMail.close();    
}
Vincent Robert
Doesn't seem to work in IE 8. wndMail is null, according to the debugger.
Eugene Katz
Sorry to hear that. It's from an old project using IE6. Feel free to edit to improve :)
Vincent Robert
Can't find a solution so far.
Eugene Katz
A: 

@Sven

But the mailto action don't send the mail, it only calls the client default email application and create a new mail, but without sending it. So that Such malware site can't send spam without user colaboration.

I only want javascript to format the body of the message, not to send it, but viewing the answers this is not possible.

Telcontar