Use Javascript to create an HTML email in Microsoft Outlook

后端 未结 4 1753
野性不改
野性不改 2020-12-07 23:47

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 00:03

    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);
    })();
    
    
    
      
    

提交回复
热议问题