xreef / EMailSender

Arduino, esp32, Esp8266 EMailSender with Arduino IDE, simple library to send email via smtp with attachments.
https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
MIT License
74 stars 26 forks source link

Email attachment deletes all files in LittleFS #37

Closed Andy2051 closed 1 year ago

Andy2051 commented 1 year ago

Arduino 1.8.9 compiler, esp8266 and LittleFS.

When I attempt to add an attachment to an email, it deletes all the files in the file system. I have done this several times. emails without attachments work fine.

Files before sending email (also visible in filezilla), generated as output at the beginning of setup:

Listing directory: /
current.txt Size: 145
data Size: 0 <<<< a directory, not deleted
format.txt Size: 17
history.csv Size: 1248
previous.txt Size: 138
sensor.log Size: 2527  <<<< the file I am trying to attach
settings.txt Size: 1000
usage.csv Size: 81

after attempting to send email

Listing directory: /
data Size: 0

filezilla also shows the root directory empty.

The email is run as a function at the end of setup for testing:

  Serial.println("STARTUP EMAIL");
  StartupEmail(); 
  Serial.println("END STARTUP EMAIL");

Where StartupEmail() is:

EMailSender MyEmail(EmailFrom,FromPwd);  //defined earlier

void StartupEmail() { 
  EMailSender::EMailMessage message;
  message.subject = ReStartTitle;
  unsigned long mytime = rtc.getEpoch();
  message.message = datestr(mytime,"%d %b %Y, %H:%M") + ReStartMsg;

  EMailSender::FileDescriptior fileDescriptor[1];
  fileDescriptor[0].filename = F("sensor.log");
  fileDescriptor[0].url = F("/sensor.log");
  fileDescriptor[0].mime = MIME_TEXT_PLAIN;
  fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_LITTLE_FS;
  EMailSender::Attachments attachs = {1, fileDescriptor};

  EMailSender::Response resp = MyEmail.send(EmailTo,message,attachs);
  Serial.print(Estatus); Serial.println(resp.status);
  Serial.print(Ecode); Serial.println(resp.code);
  Serial.print(Edescript); Serial.println(resp.desc);
} //end function StartupEmail

Output generated is:

STARTUP EMAIL
status=0
code=404
description=Error opening attachments file /sensor.log
END STARTUP EMAIL

It hangs for some time, maybe 30 seconds or longer between echoing START EMAIL and the other output. Without the code for the attachment, it works and the email is delivered, email body: 17 Jan 2023, 12:21 - Oil sensor restarted.

I can live without email attachments but it would be nice to find out what is going wrong.

thanks

Andy

xreef commented 1 year ago

Hi Andy, Please share all your code, and we try to check It. Thanks Renzo

Andy2051 commented 1 year ago

Renzo, Thanks for replying and offering to have a look. It is nearly a year since I last asked you a question. I had to put the project on hold because other things took priority. Attached project files zipped up.

I have also attached a pdf that gives you the circuit diagram - for information and background. The areas of interest to you:

You can ignore all the other email functions in email.cpp, I am not using them yet and email without attachments works fine. Symptoms, as described on github.

The main loop reads the sensor, The JSN-SRO4 ultra sonic sensor is not particularly consistent (or reliable) so it takes lots of readings. It then goes to sleep for an hour before repeating. If you try to run the code, as you will have no sensor attached, you may get a lot of errors reported in the log file sensor.log. Grateful for any input you can provide, sending an attachment is "nice to have" not essential. It is a case of: have I done something obviously wrong? regards Andy

Hi Andy,

Please share all your code, and we try to check It.

Thanks Renzo

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: < @.***>

On Tue, 2023-01-17 at 22:53 -0800, Renzo Mischianti wrote:

xreef commented 1 year ago

Hi, It's seems no file is attached. Bye Renzo

Andy2051 commented 1 year ago

Obviously got stripped from the email. :( email-problems.zip tank-sensor.pdf

xreef commented 1 year ago

Hi Andy, It seems all ok, I must reproduce the project entirely, but from the close, I think that the problem can be a memory leak. The Ftp server and Email get a lot of memory; try to add some checks on the memory usage. Bye RM

Andy2051 commented 1 year ago

Thanks for the pointer, I will investigate.