I have a project to finish and a little problem blocking me: I create an interface for the user to report bugs, his request is forwarded by a programm called smtpJS. But when he try to join file, they don’t send correctly.
The user upload their files with an classic input type file, but for send them I need to convert the files in base x64 under form of dataURI.
This is my code :
let allFilesConverted=[];
let file;
let reader;
let fileName;
let dataUri;
for (let i =0;i<files.length;i++){
file = files[i];
file = files[i];
reader = new FileReader();
reader.onloadend = () => {
fileName=file.name;
dataUri=reader.result;
allFilesConverted.push({name : fileName, data : dataUri})
};
reader.readAsDataURL(file);
};
Email.send({
Host : "smtp.elasticemail.com",
Username : "OBSEM.submitRequest@gmail.com",
Password : "***********",
To : 'obsem.reportbug@gmail.com',
From : "OBSEM.submitRequest@gmail.com",
Subject : "Request from "+pseudo.toUpperCase(),
Body : `<p>Username : `+pseudo+`
</br>Mail : `+mail+`
</br>Sujet : `+sujet+`
</br>Message : `+message+`
</br>
</br>END</p>`,
Attachments : allFilesConverted
});
console.log(allFilesConverted);
The files are pick up like this : document.getElementById("inputFile").files.
The console log is correct and display the good list. However when I open the mail , there is no file and the presentaion is quite rude (no lines returns or font-size).
If anybody got the solution for one of these problem i’ll take it. I can show you the rest of my code if you want.
Thanks in advance ! (and sorry for my bad english !)
Finnaly after try and try i resolve my problem with the article that you advised me, i just had to convert the file when the user upload it and put the result in a global var. After that i just had to send all files converted. The code is :