I\'d like to create an email from a Javascript web application. I\'m completely aware of the many SO questions on this (e.g. Open Outlook HTML with Chrome). There are prob
Using the idea of plain text eml files, I came up with this: http://jsfiddle.net/CalvT/un3hapej/
This is an edit of something I found - to create a .txt
file then download it. As .eml
files are practically .txt files, I figured this would work. And it does. I've left the textarea
with the sample email in so you can easily test. When you click on create file, it then gives you a download link to download your .eml
file. The only hurdle I can see is making the browser open the .eml
file after it has been downloaded.
EDIT: And thinking about it, as you have access to the client machines, you could set the browser to always open files of that type. For instance in Chrome, you can click on the arrow beside the download and select always open files of this type.
Here's the code
HTML:
(function () {
var textFile = null,
makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
var create = document.getElementById('create'),
textbox = document.getElementById('textbox');
create.addEventListener('click', function () {
var link = document.getElementById('downloadlink');
link.href = makeTextFile(textbox.value);
link.style.display = 'block';
}, false);
})();