JSFiddle - React, Tailwind, and code Playground

by aybalasubramanian

HTML

<textarea id="textbox" style="width: 300px; height: 100px;">
To: User <[email protected]>
Subject: Subject
X-Unsent: 1
Content-Type: text/html

<html>
<body>
<img src="http://www.laurell.com/images/logo/laurell_logo_storefront.jpg" width="200" height="57" alt=""/>
</body>
</html>
</textarea>
   
   <button id="create">Create file</button><br /><br />
                    <a download="message.eml" id="downloadlink">Download</a>

JavaScript

var create = document.getElementById('create');
    var textFile = null,
    makeTextFile = function (text) {
      var data = new Blob([text], {type: 'text/plain'});
      if (textFile !== null) {
        window.URL.revokeObjectURL(textFile);
      }
      // setTimeout(function(){
      textFile = window.URL.createObjectURL(data);
      return textFile;
      // },100);

    };
    let emlString = "To: User <[email protected]> \nSubject: Subject \nX-Unsent: 1 \nContent-Type: text/html \n<html> \n<head> \n</head> \n<body> \n<img src='http://www.laurell.com/images/logo/laurell_logo_storefront.jpg' width='200' height='57' alt=''>";

    create.addEventListener('click', function () {
      //debugger;
      var link = document.getElementById('downloadlink');
      var textbox = document.getElementById('textbox');
      //link.href = makeTextFile(emlString);
      //link.style.display = 'block';
      link.href = makeTextFile(textbox.value);
      /* window.location.href =
      "mailto:" +
      to_email +
      "?subject=" +
      subj +
      "&body=" +
      makeTextFile(emlString); 
      // +
      // lastFewLines +
      // greetings; */
    }, false);