Send email with smtpJS

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 = () => {
            allFilesConverted.push({name : fileName, data : dataUri})

      Host : "",
      Username : "",
      Password : "***********",
      To : '',
      From : "",
      Subject : "Request from "+pseudo.toUpperCase(),
      Body : `<p>Username : `+pseudo+`
      </br>Mail : `+mail+`
      </br>Sujet : `+sujet+`
      </br>Message : `+message+`
      Attachments : 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 !)

Yes, i look and test his code but the result, was the same.

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 :

<input type='file' accept="image/*,video/*,.pdf,.txt,.html,.js,.css,.odt,.odp,.odf,.docx" name='fichiersSupp' id="fileInput" onchange="convertFile()"/>
function convertFile(){
  var reader;
  var dataUri;
  var file = document.getElementById("fileInput").files[document.getElementById("fileInput").files.length-1];
    reader = new FileReader();
    reader.onload = function () {
      dataUri = "data:" + file.type + ";base64," + btoa(reader.result);
    reader.onloadend= function(){
      allConvertedFiles.push({name :, data : dataUri});
      Host : "",
      Username : "",
      Password : "*******",
      To : '',
      From : "",
      Subject : "Request from "+pseudo.toUpperCase(),
      Body : `bodyContent`,

      Attachments : allConvertedFiles

And, that’s it !

Thanks for your help !

It’s just a school project so i don’t need to hide username and pass.
I call the function in the event onchange of the input , it’s write at the top.

Bonjour Tikax,

merci pour ton post et désolé de le réveiller :wink:

J’essaye de faire un formulaire de contact sous REACT avec l’envoi de fichiers.

Je pense qu’il y a quelques chose que je n’ai pas compris dans tes lignes de codes.

Pourrais tu me partager le code complet de ton formulaire voir si je peux l’adapter a REACT, stp?

bien à toi

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.