Empty attachment

Viewing 12 reply threads
  • Author
    Posts
    • #6495
      Norbert

        Hi,

        Esp8266 Wemos D1 Mini, emailsender is working fine except attachment. It can attach the file with correct name/extension but  if I want to open it it is always empty. No content.

        80-90bytes in size on arrival but when I want to open a txt file attached it is empty. I tried to change mime type or encode 64 true/false but no change.

         

      • #6497
        Renzo Mischianti
        Keymaster

          Hi Norbert,

          If the file It’s 80byte mean the there are almost 80 characters. It’s very strange, try to change extension, like xml or similar.

          Please give me a feedback.

          Bye Renzo

        • #6507
          Michael

            Hey there,

            i have the same exact problem….

            Your Lib works very nice! But the attachments of the recieved e-mail are empty.

            I also use the WEMOS D1Mini Pro Board with an SD Card (also tried Spiffs, but also blank attachments)

            @Mischianti: Did your attachments work? (i’m asking because you mentioned in your article, that you’ve tested it on an Wemos D1 Mini)

            I also tried using .xml .csv .pdf file extension with and without enabled encoding 64.

            Have you any clue what could be the reason for these empty attachments? :/

             

            Thanks a lot!

            Greetings from Germany

          • #6508
            Renzo Mischianti
            Keymaster

              Hi Michael,

              I tested now my WeMos D1 mini, and the txt attachment works correctly.

              But It’s strange because if the file It’s 80byte mean that there are 80 character, so It isn’t empty.

              Can you send me your code PLZ.

              Bye Renzo

               

            • #6510
              Michael

                Thanks for your quick response!

                I took the example code, provided in your library and changed minor things….:

                
                /*
                 * EMailSender library for Arduino, esp8266 and esp32
                 * esp8266 Gmail send example with 2 attach loaded in SPIFFS
                 *
                 * The base64 encoding of the image is slow, so be patient
                 *
                 * http://mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
                 *
                 */
                
                #include "Arduino.h"
                
                #include 
                #include 
                
                // Libraries for SD card
                #include "FS.h"
                #include "SD.h"
                
                
                uint8_t connection_state = 0;
                uint16_t reconnect_interval = 10000;
                
                EMailSender emailSend("XXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX");
                
                uint8_t WiFiConnect(const char *nSSID = nullptr,
                		const char *nPassword = nullptr) {
                	static uint16_t attempt = 0;
                	Serial.print("Connecting to ");
                	if (nSSID) {
                		WiFi.begin(nSSID, nPassword);
                		Serial.println(nSSID);
                	}
                
                	uint8_t i = 0;
                	while(WiFi.status()!= WL_CONNECTED && i++ < 50 ) {	delay(200); Serial.print(".");}++attempt;
                			Serial.println("");
                			if (i == 51) {
                				Serial.print("Connection: TIMEOUT on attempt: ");
                				Serial.println(attempt);
                				if (attempt % 2 == 0)
                					Serial.println(
                							"Check if access point available or SSID and Password\r\n");
                				return false;
                			}
                			Serial.println("Connection: ESTABLISHED");
                			Serial.print("Got IP address: ");
                			Serial.println(WiFi.localIP());
                			return true;
                		}
                		void Awaits() {
                			uint32_t ts = millis();
                			while (!connection_state) {
                				delay(50);
                				if(millis() > (ts + reconnect_interval) && !connection_state ) {
                						connection_state = WiFiConnect();
                						ts = millis();
                					}
                				}
                			}
                
                			void setup() {
                				Serial.begin(9600);
                				const char *ssid = "XXXXXXXXXXXXXXXXXXXXX";
                				const char *password = "XXXXXXXXXXXXXXXXXXXXX";
                
                				if (!SD.begin(15)) {
                					Serial.println("An Error has occurred while mounting SD");
                					return;
                				}
                				Serial.println("SD OK");
                
                				/*Serial.println("ReadDir");
                				 Dir dir = SPIFFS.openDir("/");
                				 while (dir.next()) {
                				 Serial.print(dir.fileName());
                				 if(dir.fileSize()) {
                				 File f = dir.openFile("r");
                				 Serial.println(f.size());
                				 }
                				 }
                				 */
                
                				connection_state = WiFiConnect(ssid, password);
                				if (!connection_state) // if not connected to WIFI
                					Awaits(); // constantly trying to connect
                				Serial.println("CONNECTED");
                				EMailSender::EMailMessage message;
                				message.subject = "XXXXXXXXXXXXXXXXXXXXX";
                				message.message = "XXXXXXXXXXXXXXXXXXXXX";
                				Serial.println("Point0");
                				EMailSender::FileDescriptior fileDescriptor[4];
                
                				fileDescriptor[0].filename = F("test.txt");
                				fileDescriptor[0].url = F("/test.txt");
                				fileDescriptor[1].mime = "text/plain";
                				fileDescriptor[0].storageType =
                						EMailSender::EMAIL_STORAGE_TYPE_SD;
                
                				Serial.println("Point1");
                
                				fileDescriptor[1].filename = F("test.pdf");
                				fileDescriptor[1].url = F("/test.pdf");
                				fileDescriptor[1].mime = "application/pdf";
                				fileDescriptor[1].encode64 = true;
                				fileDescriptor[1].storageType =
                						EMailSender::EMAIL_STORAGE_TYPE_SD;
                
                				fileDescriptor[2].filename = F("test.xml");
                				fileDescriptor[2].url = F("/test.xml");
                				fileDescriptor[2].mime = "application/xml";
                				fileDescriptor[2].encode64 = true;
                				fileDescriptor[2].storageType =
                						EMailSender::EMAIL_STORAGE_TYPE_SD;
                
                				fileDescriptor[3].filename = F("test.csv");
                				fileDescriptor[3].url = F("/test.csv");
                				fileDescriptor[3].mime = "text/csv";
                				fileDescriptor[3].encode64 = true;
                				fileDescriptor[3].storageType =
                						EMailSender::EMAIL_STORAGE_TYPE_SD;
                
                				EMailSender::Attachments attachs = { 4, fileDescriptor };
                				Serial.println("Point2");
                				EMailSender::Response resp = emailSend.send(
                						"XXXXXXXXXXXXXXXXXXXXX", message, attachs);
                				Serial.println("Point3");
                				Serial.println("Sending status: ");
                
                				Serial.println(resp.status);
                				Serial.println(resp.code);
                				Serial.println(resp.desc);
                
                			}
                
                			void loop() {
                
                			}
                
                

                 

              • #6512
                Renzo Mischianti
                Keymaster

                  Hi Michael,
                  there is an error on index of txt file, so the mime type is not set

                  
                  				fileDescriptor[0].filename = F("test.txt");
                  				fileDescriptor[0].url = F("/test.txt");
                  				fileDescriptor[1].mime = "text/plain";
                  				fileDescriptor[0].storageType =
                  						EMailSender::EMAIL_STORAGE_TYPE_SD;
                  
                  

                  I rewrite the sketch and put some example, I test It with SPIFFS and work correctly

                  I attach the sketch with all sampe file.

                  Bye Renzo

                • #6514
                  Norbert

                    I use spiffs by the way.

                    Outlook displays 80byte for the attachment, after saving to a folder it is 0 bytes in a file explorer.

                  • #6515
                    Renzo Mischianti
                    Keymaster

                      Try to send the attach via classic email from gmail or similar.

                      I think the problem is outlook.

                       

                    • #6530
                      Norbert

                        You got it. I checked it on the web surface of gmail and the attachments have arrived correctly but not with outlook.

                        Do you have any idea what is the problem with outlook?

                         

                      • #6531
                        Renzo Mischianti
                        Keymaster

                          I check on the web and seems there are a lot of problems with Outlook,

                          can you try to send the txt file directly from gmail and check in outlook?

                           

                          Bye Renzo

                        • #6532
                          MH
                          Participant

                            Hello together, i think i solved the Problem 🙂

                            Now all four tested file extensions work! (xml,pdf,txt,csv) there was an issue in your library:

                            in EMailSender.cpp Line 386:

                            Original: client.println();

                            New: client.println("\n");

                            Thanks for your help and great work!

                            I’m very happy, that it works now!

                            I put a Screenshot and the .cpp file below (had to rename it to .txt)

                             

                          • #6534
                            Norbert

                              Yes it is working now.

                              Thank you for your help!

                            • #6535
                              Renzo Mischianti
                              Keymaster

                                Thanks to all,

                                I’m going to release a new library version with this fix and new distribution list features.

                                Thanks again Renzo

                            Viewing 12 reply threads
                            • You must be logged in to reply to this topic.
                            Exit mobile version