Copy mail from Outlook and paste msg-file to file input

586 Views Asked by At


Copying different files into the input such as xlxs, png, msg, etc. works perfectly. What I wish to accomplish is being able to copy mails directly from Outlook into the input (as msg-files).

The problem:

If I copy a mail from Outlook with the current solution I get vague information such as the subject, sent date, receiver etc - Just as if you would paste the clipboard into notepad.

The Goal:

If you copy a mail from Outlook into a word document for example, it creates a clickable msg-file. This is the file I'd like to paste into my input.

Right now, I've to copy the mail from Outlook, paste it into word, copy it again, to finally being able to paste the msg-file into the input

HTML:

<div id="documentUploadDiv">
  <div id="filedataholder" filebase64data="" hasfile="false"></div>
  <div id="filereaderdialog_filegroup">
    <input type="file" id="filedatareader_filegroup">
  </div>
</div>

Script:

window.addEventListener('paste', e => {
try{          
    $('#filedatareader_filegroup').get(0).files = e.clipboardData.files;
    $('#filedatareader_filegroup').trigger("change");

    var reader = new FileReader();
    reader.readAsDataURL(e.clipboardData.files[0]);

    $("#filedataholder").attr("filebase64data", reader.result) 
  
    }catch(e){
        console.error(e)
    }
});
1

There are 1 best solutions below

1
Dmitry Streblechenko On

That is because Outlook copies its message in multiple clipboard formats, but FileContents/Filename are not available since there is no real file on the file system.

See Upload fails when user drags and drops attachment from email client for a similar issue.

enter image description here