Reputation: 4870
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
Upvotes: 19
Views: 36540
Reputation: 4585
You can create a mailto-link and fire it using javascript:
var mail = "mailto:[email protected]?subject=New Mail&body=Mail text body";
var mlink = document.createElement('a');
mlink.setAttribute('href', mail);
mlink.click();
Upvotes: 1
Reputation: 36150
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();
}
Upvotes: 18
Reputation: 6102
You more or less only have two alternatives when sending mail via the browser..
Upvotes: 6
Reputation: 18368
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!
Upvotes: 4
Reputation: 44613
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.
Upvotes: -1