Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use JavaScript to create a client side email?

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

like image 383
Telcontar Avatar asked Aug 11 '08 07:08

Telcontar


2 Answers

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 = "";//between the speech mark goes the receptient. Seperate addresses with a ;
var body = ""//write the message text between the speech marks or put a variable in the place of the speech marks
var subject = ""//between the speech marks goes the subject of the message
var href = "mailto:" + addresses + "?"
         + "subject=" + subject + "&"
         + "body=" + body;
var wndMail;
wndMail = window.open(href, "_blank", "scrollbars=yes,resizable=yes,width=10,height=10");
if(wndMail)
{
    wndMail.close();    
}
like image 76
Vincent Robert Avatar answered Sep 27 '22 20:09

Vincent Robert


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.
like image 22
Lars Mæhlum Avatar answered Sep 27 '22 22:09

Lars Mæhlum