I'm creating an eml file on my website as a text/html type through JavaScript for my users to download and use as a template. I want to add an attachment to this eml file so that when its downloaded the attachment is automatically attached to the email. I researched a lot on this problem before asking this question but i could not find a suitable answer/solution. So my question is, how can i possibly add an attachment to the eml file through JavaScript?
I have tried adding a link to the eml file, i.e. through the that points to the attachment, which is in the same folder as my coding files. However, i get an error saying the file could not be located when i click the link in outlook before and after its sent.
var emailTo, emailSubject, htmlDocumentContent;
emailSubject = "User Account Created";
emailTo = "[email protected]";
htmlDocumentContent = "html code goes here";
//creating the eml file
var emlContent = "data:message/rfc822 eml;charset=utf-8,";
emlContent += 'To: '+emailTo+'\n';
emlContent += 'Subject: '+emailSubject+'\n';
emlContent += 'X-Unsent: 1'+'\n';
emlContent += 'Content-Type: text/html'+'\n';
emlContent += ''+'\n';
emlContent += htmlDocumentContent;
var encodedUri = encodeURI(emlContent); //encode spaces etc like a url
var a = document.createElement('a'); //create a link element in the document
var linkText = document.createTextNode("fileLink"); //create the file's link to the element
a.appendChild(linkText); //append the file's link to the element
a.href = encodedUri;
a.id = 'fileLink';
a.download = 'JDE New User Email.eml';
a.style = "display:none;"; //hidden link
document.body.appendChild(a);
document.getElementById('fileLink').click(); //click the link
what i want to add to this code, or this eml file, is a pdf attachment so that when the user downloads it, it had the pdf file automatically attached to it.
Thank you very much for your help in advance.