Home › Forums › The libraries hosted on the site › EMailSender send email with attachments › Raspberry Pico W & EmailSender
Tagged: EMailSender, Raspberry Pico W
- This topic has 17 replies, 2 voices, and was last updated 1 year, 5 months ago by
Erick.
-
AuthorPosts
-
-
15 January 2023 at 20:42 #23916
Hello. Thank you for the EmailSender library which is really useful.
I’m trying to use it on a Raspberry Pico W environment
and the ESP8266SdFat library on SPI 1.I defined in the EMailSenderKey.h file
#define SD_CS_PIN 13 instead of #define SD_CS_PIN SSThe mail message part is ok, but not the attachment of the .CSV file
If you can help me.
Thank you.Bord is Raspberry Pi W with :
Raspberry Pi RP2040 Core platform file By Earle F. Philhower
name=Raspberry Pi RP2040 Boards(2.3.3)
version=2.3.3#include <EMailSender.h> #include <WiFi.h> #include "SdFat.h" #include <stdio.h> #include "sdios.h" #include "pico/stdlib.h" #include "hardware/i2c.h" #include "hardware/gpio.h" #include "SdFat.h" // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h, // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT. #define SD_FAT_TYPE 1 // Try max SPI clock for an SD 50. Reduce SPI_CLOCK if errors occur. #define SPI_CLOCK SD_SCK_MHZ(80) // Try to select the best SD card configuration. #if HAS_SDIO_CLASS #define SD_CONFIG SdioConfig(FIFO_SDIO) #elif ENABLE_DEDICATED_SPI #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK) #else // HAS_SDIO_CLASS #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK) #endif // HAS_SDIO_CLASS #if SD_FAT_TYPE == 0 SdFat sd; File file; File root; #elif SD_FAT_TYPE == 1 SdFat32 sd; File32 file; #elif SD_FAT_TYPE == 2 SdExFat sd; ExFile file; #elif SD_FAT_TYPE == 3 SdFs sd; FsFile file; #else // SD_FAT_TYPE #error Invalid SD_FAT_TYPE #endif // SD_FAT_TYPE //—————————————————————————— // store error strings in flash memory #define error(s) sd.errorHalt(PSTR(s)) //—————————————————————————— uint8_t connection_state = 0; uint16_t reconnect_interval = 10000; EMailSender emailSend(email_login, email_password, email_from, smtp_server, smtp_port); 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(115200); delay(2000); // initialisation carte SD if (!sd.begin(SD_CS_PIN)) { Serial.println("WARNING initialization SD failed!"); delay(1000); } else { Serial.println(F("Card is present.")); } // Show capacity and free space of SD card Serial.print(F("Capacity of card: ")); Serial.print(long(sd.card()->sectorCount() >> 1)); Serial.println(F(" kBytes")); Serial.print(F("\nList of files on the SD.\n")); sd.ls(LS_R); connection_state = WiFiConnect(ssid, password); if (!connection_state) // if not connected to WIFI Awaits(); // constantly trying to connect EMailSender::FileDescriptior fileDescriptor[1]; fileDescriptor[0].filename = F("Bernard_05011701_2023.CSV"); fileDescriptor[0].url = F("/Bernard_05011701_2023"); fileDescriptor[0].mime = MIME_TEXT_PLAIN; fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD; EMailSender::Attachments attachs = { 1, fileDescriptor }; EMailSender::EMailMessage message; message.subject = "Data File Result"; message.message = "Resultat de l’annalyse.\n\r 1er test sans piece attachée\n\r NE PAS REPONDRE A CETTE ADRESSE."; Serial.println("All structure created!"); EMailSender::Response resp = emailSend.send("xxx@gmx.fr", message, attachs); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); } void loop() { }
Out Serial.print :
Card is present. Capacity of card: 7864320 kBytes List of files on the SD. .eeprom .wifi .log.csv Bernard_05011701_2023.CSV Connecting to Linux Connection: ESTABLISHED Got IP address: 192.168.1.32 All structure created! ONLY ONE RECIPIENTmiltiple destination and attachments Insecure client:0 smtp.free.fr 465 220 smtp6-g21.free.fr ESMTP Postfix HELO mischianti 250 smtp6-g21.free.fr AUTH LOGIN: 334 VXNlcm5hbWU6 Encoding xxxxx@free.fr 13 ZjVleG9AZnJlZS5mcg== Encoding xxxx@free.fr 13 334 UGFzc3dvcmQ6 Encoding pwd 8 c3U4ODY3aTE= Encoding pwd 8 235 2.7.0 Authentication successful MAIL FROM: <xxxx@free.fr> 250 2.1.0 Ok RCPT TO: <xxxx@gmx.fr> 250 2.1.5 Ok DATA: 354 End data with <CR><LF>.<CR><LF> Message end 250 2.0.0 Ok: queued as ABBC37802E5 221 2.0.0 Bye Sending status: 1 0 Message sent!
-
This topic was modified 1 year, 10 months ago by
Renzo Mischianti.
-
This topic was modified 1 year, 10 months ago by
Renzo Mischianti.
-
This topic was modified 1 year, 10 months ago by
-
16 January 2023 at 14:41 #23919
Hi Erick,
I think you don’t enableSTORAGE_SD
on external storage inEMailSenderKey.h
.
Please paste yourEMailSenderKey.h
.
Bye Renzo -
16 January 2023 at 17:06 #23946
Thank’s for your replay Renzo
I think that’s it too, because the latest debug lines are :
————————————-
250 2.1.5 OkDATA:
354 End data with <CR><LF>.<CR><LF>Array: Bernard_05011701_2023.CSV
–frontier
Content-Type:
text/csv
; charset=”UTF-8″
Readed filename: Bernard_05011701_2023.CSV
Sending status:
0
500
EMAIL_STORAGE_TYPE_SD not enabled on EMailSenderKey.h
———————————-Attachments:
You must be logged in to view attached files. -
17 January 2023 at 08:07 #23949
Hi,
change this#ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040 #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_NONE #endif
to
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040 #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD #endif
Bye Renzo
-
17 January 2023 at 11:55 #23965
Hi Renzo
New problem …
with :// Arduino SAMD microcontrollers configuration #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040 #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_NONE #endif
and
//#define SD_CS_PIN SS #define SPIFM_CS_PIN SS
compile ok Card is present. Capacity of card: 7864320 kBytes List of files on the SD. .eeprom .wifi .log.csv test.txt logo.jpg Bernard_05011701_2023.CSV Connecting to Linux Connection: ESTABLISHED Got IP address: 192.168.1.32 All structure created!
When :
#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD
problem to compil :
In file included from /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:35: /home/erick/Arduino/libraries/EMailSender/EMailSender.h:306: warning: "EMAIL_NETWORK_CLASS" redefined 306 | #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS | In file included from /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:35: /home/erick/Arduino/libraries/EMailSender/EMailSender.h:186: note: this is the location of the previous definition 186 | #define EMAIL_NETWORK_CLASS WiFiClient | /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp: In member function 'EMailSender::Response EMailSender::send(const char**, byte, byte, byte, EMailSender::EMailMessage&, EMailSender::Attachments)': /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:907:39: error: 'SD_CS_PIN' was not declared in this scope; did you mean 'SPIFM_CS_PIN'? 907 | if(!EXTERNAL_STORAGE_CLASS.begin(SD_CS_PIN)){ | ^~~~~~~~~ | SPIFM_CS_PIN exit status 1 Errore durante la compilazione per la scheda Raspberry Pi Pico W. -----------
SS pin is define in the top with , and ok to SD access.
const uint8_t SD_CS_PIN = SDCARD_SS_PIN; -
17 January 2023 at 12:31 #23967
Hi Erick,
you can’t remove thedefine
in the library header//#define SD_CS_PIN SS
If you put define it externally It survives in the external context, not in the internal of the library.
Bye Renzo
-
17 January 2023 at 14:53 #23968
It’s better but another problem
Here is the SD_FAT_TYPE
// 1 for FAT16/FAT32
#define SD_FAT_TYPE 1
and Sdat library is ESP8266SdFat contained in Earle F. Philhower RP2040 package 2.7.1Card is present.
Capacity of card: 7864320 kBytes
List of files on the SD.
.eeprom
.wifi
.log.csv
test.txt
logo.jpg
Bernard_05011701_2023.CSVConnecting to Linux
Connection: ESTABLISHED
Got IP address: 192.168.1.32
All structure created!
.
.
.
..
RCPT TO: <ffffff@gmx.fr>
250 2.1.5 OkDATA:
354 End data with <CR><LF>.<CR><LF>Array: test.txt
–frontier
Content-Type:
text/plain
; charset=”UTF-8″
Readed filename: test.txt
SD Check
Sending status:
0
500
Error on startup SD filesystem! -
17 January 2023 at 15:52 #23969
Hi Erick,
trySTORAGE_SDFAT2
.
Bye RM -
17 January 2023 at 17:02 #23970
Thank you for your speed Renzo.
With :
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
#define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
#define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT2
#endifCompil problem :
|
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp: In member function ‘EMailSender::Response EMailSender::send(const char**, byte, byte, byte, EMailSender::EMailMessage&, EMailSender::Attachments)’:
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:935:54: error: conversion from ‘File32’ to non-scalar type ‘FsFile’ requested
935 | EMAIL_FILE_EX myFile = EXTERNAL_STORAGE_CLASS.open(attachments.fileDescriptor[i].url.c_str());
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:985:29: error: ‘SdFat’ {aka ‘class SdFat32’} has no member named ‘end’
985 | EXTERNAL_STORAGE_CLASS.end();
| ^~~ -
19 January 2023 at 14:36 #24002
Hello Renzo
After several type of tests, I arrived at something positive.
If this can be a clue for you, here is what I did to get it to work properly.
Erick/* in Key.h #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040 #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS -> //#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD -> #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT2 #endif -> #define SD_CS_PIN 13
in .h
Ligne 290#define EMAIL_FILE_READ_EX FILE_READ -> //#define EMAIL_FILE_EX FsFile -> #define EMAIL_FILE_EX File32
in .cpp
line 982if (sdActive){ DEBUG_PRINTLN(F(“SD end”)); #ifndef ARDUINO_ESP8266_RELEASE_2_4_2 -> //EXTERNAL_STORAGE_CLASS.end(); #endif DEBUG_PRINTLN(F(“SD end 2″)); } */
Debug out :
DATA: 354 End data with <CR><LF>.<CR><LF> Array: Bernard_05011701_2023.CSV –frontier Content-Type: text/csv ; charset=”UTF-8” Readed filename: Bernard_05011701_2023.CSV SD Check Open file: OK NORMAL Message end 250 2.0.0 Ok: queued as 596F678035E 221 2.0.0 Bye Sending status: 1 0 Message sent!
-
20 January 2023 at 08:55 #24005
Hi Erick,
I understand the ESP8266SdFat given by Raspberry is different from the original one, so I integrate your change in the version that you can find in the master branch.#ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040 #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT_RP2040_ESP8266 #endif
Please try it and give me feedback.
Thanks, Renzo -
20 January 2023 at 10:05 #24008
OK Many Thank’s Renzo IT’S SUPER GOOD !
Another question if I can afford Renzo:
With some provider the message is indeed sent, but not delivered.
Probably because of HELO contents.
Can it be contained in an external const char* if it’s possible ?
Thank you for all.
Erick——————————————
250 2.1.5 Ok
DATA:
354 End data with <CR><LF>.<CR><LF>
Array: Bernard_05011701_2023.CSV
–frontier
Content-Type:
text/csv
; charset=”UTF-8″
Readed filename: Bernard_05011701_2023.CSV
SD Check
Open file:
OK
NORMAL
Message end
250 2.0.0 Ok: queued as 05021780304
221 2.0.0 Bye
Sending status:
1
0
Message sent! -
20 January 2023 at 10:17 #24009
Hi,
you can change HELO contents withsetPublicIpDescriptor("Pippo");
Bye Renzo
-
20 April 2023 at 11:47 #25386
Hi Renzo
A new problem, with a file join type csv.
When a line is longer than 1071 characters, the line is broken with a newline character.
And also a newline character is added at the end of the file. (For this it is not too annoying).Thank you
Erick
-
10 December 2023 at 10:51 #28633
Hi Renzo
i am back,
Now with RP2040 I no longer use SdFat but SDFS instead
can you add with RP2040 SDFS#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFS
https://arduino-pico.readthedocs.io/en/latest/fs.html
Thank’s you.
Erick -
11 December 2023 at 16:35 #28642
Hi Erick,
Do you already try to set the SD filesystem in the external storage?
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.