Giter Site home page Giter Site logo

xreef / emailsender Goto Github PK

View Code? Open in Web Editor NEW
74.0 8.0 26.0 189 KB

Arduino, esp32, Esp8266 EMailSender with Arduino IDE, simple library to send email via smtp with attachments.

Home Page: https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/

License: MIT License

C++ 84.36% C 15.64%
email-sender smtp arduino arduino-library esp8266 gmail-smtp esp32 rp2040 raspberry pico-w

emailsender's Introduction

Support forum EMailSender English
Forum supporto EMailSender italiano

Library to send EMail with attachments

Arduino (support W5100 like must be set, and ENC28J60 via UIPEthernet), esp8266 (SPIFFS, LittleFS and SD) (core <=2.4.2 must be set) and esp32 (SPIFFS, LITTLEFS, Ffat and SD), Arduino WiFiNINA SAMD devices (Arduino MKR WiFi 1010, Vidor 4000 UNO WiFi Rev.2 ecc.) (SD).

Complete english tutorial

Tutorial completo in italiano

Change log

  • 14/03/2024: v3.0.14 Support Arduino GIGA WiFi
  • 31/10/2023: v3.0.13 Fix wrong implementation of FORCE_DISABLE_SSL
  • 17/10/2023: v3.0.12 Fix warnigs of variable not used #43 thanks to @Patriboom @Andy2015
  • 16/02/2023: v3.0.11 Add support for Ethernet_Generic
  • 20/01/2023: v3.0.10 Add the management of ESP8266SdFat library on Raspberry Pi Pico #forum
  • 17/01/2023: v3.0.10 Add the mamagement of auto check of response number #36 thanks to @HACKER-3000 @H3
  • 13/01/2023: v3.0.9 Fix external storage error 404 (#forum
  • 05/01/2023: v3.0.8 Fix distribution list examples
  • 22/09/2022: v3.0.7 Add Raspberry Pi Pico W and rp2040 boards
  • 20/09/2022: v3.0.7 Add STM32 management for https://github.com/rogerclarkmelbourne/Arduino_STM32 library.
  • 16/08/2022: v3.0.6 Add FORCE_DISABLE_SSL to disable SSL if present
  • 19/07/2022: v3.0.5 Additional fix on additional response management (#26)
  • 12/07/2022: v3.0.4 Fixed attachment issue on SPIFFS and LittleFS
  • 06/07/2022: v3.0.3 Manage multiple response message after connect and HELO (#26)
  • 03/06/2022: v3.0.2 Add possibility to set additionalResponseLineOnConnection with void setAdditionalResponseLineOnConnection(uint8_t numLines = 0), needed if on connection you receive 220 response as error, and add Ethernet2.
  • 20/05/2022: v3.0.1 Put inside scope the client declaration (if you don't use SSLClient) for backward compatibility
  • 18/05/2022: v3.0.0 Add STM32 support. Add SSLClient integration to allow send Email with SSL encryption (like Gmail) with ethernet (tested with STM32, ESP32, w5500, and enc28j60), minor fix
  • 12/04/2021: v2.4.3 Fix multiple email send
  • 12/04/2021: v2.4.1 Add support for LITTLEFS and Ffat on esp32 and fix certificate verification from esp32 core 1.0.5
  • 18/03/2021: v2.3.0 Add support for LittleFS on esp8266
  • 02/01/2021: v2.2.0 New support for SAMD devices via WiFiNINA (Arduino MKR WiFi 1010, Arduino Vidor 4000 and Arduino UNO WiFi Rev.2 ecc.).
  • 01/01/2021: v2.1.5 Add possibility to use EHLO instead of HELO, and SASL login.
  • 27/11/2020: v2.1.4 Add more constructor to allow more structure for distribution list (now const char*, char* and String array are supported)

23/11/2020: v2.1.3 Add management of name on EMail from

Installation Tutorial:

To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder EMailSender. Check that the EMailSender folder contains EMailSender\\.cpp and EMailSender.h. Place the EMailSender library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

EMailSender library to send EMail.

With this library you can send email with attach: Arduino Network supported - w5100 like shield with Ethernet library - enc28J60 with UIPLibrary Storage support - SD

esp8266 you must pay attention, older core from 2.4.2 must be activated Storage supported - SD - SPIFFS - LittleFS

esp32 Storage supported - SD - SPIFFS - LITTLEFS - Ffat

Constructor: Default value is quite simple and use GMail as smtp server.

	EMailSender emailSend("[email protected]", "password");

If you want use onother provider you can use more complex (but simple) contructor

	EMailSender(const char* email_login, const char* email_password, const char* email_from, const char* smtp_server, uint16_t smtp_port);

You must connect to WIFI :P.

Create a message with the structure EMailMessage

    EMailSender::EMailMessage message;
    message.subject = "Subject";
    message.message = "Hi, How are you<br>Fine.";

Create array of attachments

// 		Two file
    EMailSender::FileDescriptior fileDescriptor[2];
    fileDescriptor[1].filename = F("test.txt");
    fileDescriptor[1].url = F("/test.txt");
    fileDescriptor[1].mime = MIME_TEXT_PLAIN;
    fileDescriptor[1].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;

    fileDescriptor[0].filename = F("logo.jpg");
    fileDescriptor[0].url = F("/logo.jpg");
    fileDescriptor[0].mime = "image/jpg";
    fileDescriptor[0].encode64 = true;
    fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;

    EMailSender::Attachments attachs = {2, fileDescriptor};

Send message:

    EMailSender::Response resp = emailSend.send("[email protected]", message, attachs);

Then check the response:

    Serial.println("Sending status: ");
    Serial.println(resp.code);
    Serial.println(resp.desc);
    Serial.println(resp.status);

From version 2.1.1 new features distribution list to send CC and CCn email.

Example output:

Connection: ESTABLISHED
Got IP address: 192.168.1.104
Sending status: 
1
0
Message sent!

https://downloads.arduino.cc/libraries/logs/github.com/xreef/EMailSender/

emailsender's People

Contributors

dirkx avatar h3wastooshort avatar patriboom avatar per1234 avatar xreef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emailsender's Issues

Warnings

Thanks for great work
I get warnings. See below...

In file included from src/test.cpp:275:0:
.pio/libdeps/az-delivery-devkit-v4/EMailSender/EMailSender.h:222:0: warning: "EMAIL_NETWORK_CLASS" redefined
#define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS
^
In file included from src/test.cpp:275:0:
.pio/libdeps/az-delivery-devkit-v4/EMailSender/EMailSender.h:165:0: note: this is the location of the previous definition
#define EMAIL_NETWORK_CLASS WiFiClient
^

best regards

Send user in mail

Hello,
I want to know if i can send a "user name" in a gmail mail with EmailSender.
I meen, when i receive the email, the sender name is [email protected] and i want it to be MYNAME for exemple.

I write
EMailSender emailSend("[email protected]", "pswd", "MYNAME", "smtp.gmail.com", 465);
and it s not working, the sender name is [email protected]

I try another library and it was possible..

Thanks

SMTP DATA error (503 5.5.1 RCPT first)

Hi people,
Does anyone know about this error?
I was investigating and nothing, I did not find anything relevant to solve it. I'm not sending many emails at the same time or anything weird.
Any help or something to investigate?
Thank you all !!! Below, you will find a part of the code where I involve email sending. (gmail)
Thank you
ale

P.S. I also commented the lines corresponding to SPIFFS to separate topics and the error remains the same.
#include <EMailSender.h>


   EMailSender emailSend("*************@gmail.com", "*****************", "**********@gmail.com", "Nombre", "smtp.gmail.com", 465);
    RECIPIENT_EMAIL = "**quienrecibe****@gmail.com";

    EMailSender::EMailMessage message;
    message.subject = "Curva de horno.";
    message.message = "Adjunto la curva solicitada.";

    envioFile = "quema_2022.11.05_18.37.csv"; 
    Serial.println(envioFile);
    EMailSender::FileDescriptior fileDescriptor[1];
    fileDescriptor[0].filename = (envioFile);
    fileDescriptor[0].url = ("/" + envioFile);
    fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
    fileDescriptor[0].mime = MIME_TEXT_PLAIN;
    fileDescriptor[0].encode64 = true;

    EMailSender::Attachments attachs = {1, fileDescriptor};
    Serial.println(RECIPIENT_EMAIL);
    EMailSender::Response resp = emailSend.send(RECIPIENT_EMAIL, message, attachs);

    Serial.println("Sending status: ");
    Serial.println(resp.status);
    Serial.println(resp.code);
    Serial.println(resp.desc);

configuration of html or plain text

it would be nice if EMailSender::EMailSender can config additional html or plain text, for testing i changed

client.println(F("Mime-Version: 1.0"));
client.println(F("Content-Type: text/plain; charset=UTF-8"));
client.println(F("Content-Transfer-Encoding: 7bit"));
client.println();
String body = String(email.message) + "\r\n";
client.println(body);
client.println(".");

instead of the original code

client.println(F("Mime-Version: 1.0"));
client.println(F("Content-Type: text/html; charset="UTF-8""));
client.println(F("Content-Transfer-Encoding: 7bit"));
client.println();
String body = "<html lang="en">" + String(email.message) + "";
client.println(body);
client.println(".");

and it works fine.

Gmail with attachments always times out.

All attempts to send any attachments results in

ONLY ONE RECIPIENT
multiple destination and attachments
Insecure client:0
smtp.gmail.com
465
[ 14169][D][ssl_client.cpp:176] start_ssl_client(): WARNING: Skipping SSL Verification. INSECURE!
220 smtp.gmail.com ESMTP w4-20020a056871060400b001b04277bbb3sm3204250oan.47 - gsmtp

HELO mischianti 
250 smtp.gmail.com at your service

AUTH LOGIN:
334 VXNlcm5hbWU6

Encoding
[email protected]
20
ZGF2aWRnc0BvdHRlcml6ZS5jb20=
Encoding
[email protected]
20
334 UGFzc3dvcmQ6

Encoding
****************
334 UGFzc3dvcmQ6

235 2.7.0 Accepted

MAIL FROM: <>
[ 16253][E][ssl_client.cpp:37] _handle_error(): [send_ssl_data():382]: (-80) UNKNOWN ERROR CODE (0050)
RCPT TO: <[email protected]>
DATA:
Sending status: 
0
1
SMTP DATA error! SMTP Response TIMEOUT!

abort() was called at PC 0x4018b7f6 on core 1

The board crashes and restarts.

Any ideas? The file I'm trying to send is only 48 bytes.

The sending function:

int sendEmail(fs::FS &fs, const char * path){
  File dir = SPIFFS.open("/");
    File file = dir.openNextFile();
    while (file) {
        Serial.println(file.name());
        Serial.println(file.size());

        file = dir.openNextFile();
    }
  EMailSender::EMailMessage message;
    message.subject = "New Picture!";
    message.message = "Your WiFi ESP32 Cam has sent a new picture! Enjoy!";
    EMailSender::FileDescriptior fileDescriptor[1];
    fileDescriptor[0].filename = F("msg.txt");
    fileDescriptor[0].url = F("/msg.txt");
    fileDescriptor[0].mime = "text/plain";
    fileDescriptor[0].encode64 = false;
    fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;

    EMailSender::Attachments attachs = {1, fileDescriptor};
    EMailSender::Response resp = emailSend.send(sett.receiver_email, message, attachs);
    Serial.println("Sending status: ");
    Serial.println(resp.status);
    Serial.println(resp.code);
    Serial.println(resp.desc);
}

Compilation error inside EMailSender.h:272:28

Hello,
The following error occurs when compiling the library:
In file included from E:\Mis documentos\Arduino\libraries\EMailSender-master\EMailSender.cpp:35:
E:\Mis documentos\Arduino\libraries\EMailSender-master\EMailSender.cpp: In member function 'EMailSender::Response
EMailSender::send(const char**, byte, byte, byte, EMailSender::EMailMessage&, EMailSender::Attachments)':
E:\Mis documentos\Arduino\libraries\EMailSender-master\EMailSender.h:272:28: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
#define EMAIL_FILE_READ 'r'

The correction is: #define EMAIL_FILE_READ "r"

Please, could you correct the master?
Greetings

MKR ETH Shield support

Looks like SAMD Arduinos are only supported when using WifiNIMA. Support of Arduino MKR with MKR Eth Shield would be welcome.

enhancement for attachments

I was looking for a way to add as attachment a binary blob, but the blob is in memory, not in SPIFFS nor FFat nor LittleFS nor SDCARD.

To be more precise, the image is in PSRAM, so I was looking for a way to add a binary blob image type "image/jpg" directly from "uint8_t* address" and "int length".

Is this library capable of doing that? Maybe I missed it. Otherwise it would be a nice enhancement.

Thanks

Constructed as Stack variable crashes

When EMailSender is constructed as a stack variable it crashes. This is due to the delete [] call on the variables email_login, email_from and email_password. They should be initialized to NULL pointers to allow the delete [] to work properly.

char* email_login = 0;
char* email_from = 0;
char* email_password = 0;

Could not connect to mail server, even if it's connecting.

EMailSender emailSend(email_login, email_pass, email_login, "smtp-mail.outlook.com", 587);
EMailSender::EMailMessage message;
message.subject = "Someone's home";
message.message = "I am!";
EMailSender::Response resp = emailSend.send("[email protected]", message);
Serial.println("Sending status: ");
Serial.println(resp.code);
Serial.println(resp.desc);
Serial.println(resp.status);

Result:

Sending status: 
2
Could not connect to mail server
0

My program will not connect to the Outlook SMTP mail servers, at least that's what it says.
However, I can see in Wireshark that it is communicating:
image

It's just back and forth of the ESP sending line data and the server responding with the same 220 code.
image

reference to 'File' is ambiguous

Hello, Please help me solve this problem

" C:\Users\minht\OneDrive\Documents\Arduino\libraries\EMailSender\EMailSender.h:297:25: error: reference to 'File' is ambiguous"
The problem occurs in the file EMailSender.h

image
Line 297

Static IP

the library isn`t compatible with static mode
WiFi.mode(WIFI_STA);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);

Send email to provider other than GMail, ie Office365/Outlook

As per the previous post, I am getting a similar error message when trying to use Office365 accounts ([email protected], smtp.office365.com, port 587). I believe the equivalent to Less Secure Apps with Office365 is to use an App Password instead but I've not had any luck getting this to work. Are you able to verify this works with an Office365 account by any chance? Thanks.

Office365 settings:

Server name: smtp.office365.com
Port: 587
Encryption method: STARTTLS

code:

const char* email_login = "[email protected]";
const char* email_password = "App Password";
const char* email_from = "[email protected]";
const char* name_from = "MoistureSensor";
const char* smtp_server = "smtp.office365.com";
// const int* smtp_port = 587;

EMailSender emailSend(smtp_server, email_password, email_from, name_from, 587);

Error:

00:28:41.508 -> ..........................
00:28:47.274 -> Connection: ESTABLISHED
00:28:47.274 -> Got IP address: 192.168.0.117
00:29:07.887 -> Sending status:
00:29:07.887 -> 0
00:29:07.887 -> 2
00:29:07.887 -> Could not connect to mail server

EMailSender works only with smtp.gmail.com port 465

By default, EMailSender uses smtp.gmail.com and port 465. That's coded into EMailSender.h.
I tried to use smtp.sendgrid.net, port 25 by calling:

    emailSend.setSMTPPort(smtpPort);

The platform is a nano 33 IOT.

I ran tcpdump on my firewall and found that some invalid stuff is sent prior to the HELO. It appears to be a TLS handshake which gmail handles just fine. I tried turning off isSecure:
emailSend.setIsSecure(false);
That didn't seem to help, and tcpdump still showed extraneous data being sent.

Using a secure port on sendgrid also failed to connect.

New Line Character in the message

Hi Guys,

Indeed the EMailSender works perfectly. I was trying to send a message as 5-8 lines/ paragraph but the message received in Gmail doesn't contain any new lines but only spaces.

Am I using them correctly? Please help!

Can't log into Gmail with EMailSenderESP32GMailTest sketch

I haven't been able to log into Gmail using your EMailSenderESP32GMailTest sketch with my Arduino MKR WiFi 1010 and the Arduino.h, WiFiNINA.h and EMailSender.h libraries. I get the following messages on the serial monitor:

Connection: ESTABLISHED
Got IP address: 192.168.1.42
Sending status:
0
1
SMTP Response TIMEOUT!

I've tried using the two parameter emailSend constructor with my gmail userid and password as well as the longer constructor with my gmail userid, password, mail from userid, smtp.gmail.com as the outgoing server and port 587, as well as port 465.

I went through parts 1 and 2 of your tutorial but it hasn't helped. I'm wondering if your EMailSender.h library isn't compatible with the MKR WiFi 1010.

I logged out of Google completely and logged back in with a browser to make sure my Gmail account was working and it's fine. There are no sent messages from the Arduino.

Any advice? Thanks.

SMS Message Body displays as attachment

When sending messages via ESP32 utilizing SMS email Scheme sourced from gmail account, the received message displays the subject correctly as text, but the body shows as an attachment. Happens regardless of the mime type used.
Attachment.txt

send csv file but failed

please help.

i want to send csv file from spiffs with this path

String fileName = todayDate + ".csv";
String path = "/Data Absensi/" + todayDate + ".csv";

so i will send different csv every day, but it keep giving me error when i compile it

EMailSender::FileDescriptior fileDescriptor[1];
fileDescriptor[0].filename = F(fileName);
fileDescriptor[0].url = F(path);
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
fileDescriptor[0].mime = MIME_TEXT_PLAIN;

error is

In file included from C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/Arduino.h:286,
from C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/FS.h:25,
from D:\Project\Arduino\curt2\webserver_email\webserver_email.ino:2:
D:\Project\Arduino\curt2\webserver_email\webserver_email.ino: In function 'void sendToEmail()':
webserver_email:612:36: error: initializer fails to determine size of 'pstr'
612 | fileDescriptor[0].filename = F(fileName);
C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h:39:76: note: in definition of macro 'FPSTR'
39 | #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
| ^~~~~~~~~~~~
D:\Project\Arduino\curt2\webserver_email\webserver_email.ino:612:34: note: in expansion of macro 'F'
612 | fileDescriptor[0].filename = F(fileName);
| ^
webserver_email:612:36: error: array must be initialized with a brace-enclosed initializer
612 | fileDescriptor[0].filename = F(fileName);
C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h:39:76: note: in definition of macro 'FPSTR'
39 | #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
| ^~~~~~~~~~~~
D:\Project\Arduino\curt2\webserver_email\webserver_email.ino:612:34: note: in expansion of macro 'F'
612 | fileDescriptor[0].filename = F(fileName);
| ^
webserver_email:613:31: error: initializer fails to determine size of 'pstr'
613 | fileDescriptor[0].url = F(path);
C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h:39:76: note: in definition of macro 'FPSTR'
39 | #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
| ^~~~~~~~~~~~
D:\Project\Arduino\curt2\webserver_email\webserver_email.ino:613:29: note: in expansion of macro 'F'
613 | fileDescriptor[0].url = F(path);
| ^
webserver_email:613:31: error: array must be initialized with a brace-enclosed initializer
613 | fileDescriptor[0].url = F(path);
C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h:39:76: note: in definition of macro 'FPSTR'
39 | #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
| ^~~~~~~~~~~~
D:\Project\Arduino\curt2\webserver_email\webserver_email.ino:613:29: note: in expansion of macro 'F'
613 | fileDescriptor[0].url = F(path);
| ^
Multiple libraries were found for "SD.h"
Used: C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
exit status 1
initializer fails to determine size of 'pstr'

what should i do?

Send email to provider other than Google

Please add an example for using another email account other than Google. Emailing and SMS text work great with dedicated Gmail account; thank you for the library code.

Had trouble understanding blog post: https://www.mischianti.org/2020/06/16/send-email-with-attachments-emailsender-v2-x-library-esp32-and-esp8266-part-2/

EMailSender(const char* email_login, const char* email_password, const char* email_from, const char* name_from, const char* smtp_server, uint16_t smtp_port);

When compiling; this line produces error: "expected unqualified-id before 'const'"

Maybe something I am overlooking; have not been successful in resolving this issue.

how to set EMailSender emailSend(email_login, email_password, email_from, smtp_server, smtp_port);

const char* smtp_server = "smtp-mail.outlook.com";
uint16_t smtp_port = 587;
const char* email_login = "[email protected]";
const char* email_password = "xxxxxx";
const char* email_from = "[email protected]";
const char* RECIPIENT_EMAIL = "[email protected]";
EMailSender emailSend(email_login, email_password, email_from, smtp_server, smtp_port);   

is this setting right?

[657067][E][ssl_client.cpp:37] _handle_error(): [start_ssl_client():273]: (-29184) SSL - An invalid SSL record was received
[657067][E][WiFiClientSecure.cpp:144] connect(): start_ssl_client: -29184

Email attachment deletes all files in LittleFS

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

EMailSenderEsp32GMailSPIFFSAttachTest.ino

Hello,
In this example that works fine, just a warning:
In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\__sources\esp32 s2\avecEmailsenderSpiffs2\avecEmailsenderSpiffs2.ino:17:
In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\__sources\esp32 s2\avecEmailsenderSpiffs2\avecEmailsenderSpiffs2.ino:17:
Infile included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\__sources\esp32 s2\avecEmailsenderSpiffs2\avecEmailsenderSpiffs2.ino:17:
C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\EMailSender/EMailSender.h:222: warning: "EMAIL_NETWORK_CLASS" redefined
#define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS' #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS

In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\__sources\esp32 s2\avecEmailsenderSpiffs2\avecEmailsenderSpiffs2.ino:17:
C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\EMailSender/EMailSender.h:165: note: this is the location of the previous definition
#define EMAIL_NETWORK_CLASS WiFiClient
`

if I replace the following part :

EMailSender::EMailMessage message; message.subject = "Fichier "; message.message = "Utilisation ";

EMailSender::FileDescriptior fileDescriptor[3];
fileDescriptor[2].filename = F("parcours36.gpx");
fileDescriptor[2].url = F("/parcours36.gpx");
fileDescriptor[2].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
fileDescriptor[2].mime = MIME_TEXT_PLAIN;

fileDescriptor[1].filename = F("test.txt");
fileDescriptor[1].url = F("/test.txt");
fileDescriptor[1].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
fileDescriptor[1].mime = MIME_TEXT_PLAIN;

fileDescriptor[0].filename = F("logo.jpg");
fileDescriptor[0].url = F("/logo.jpg");
fileDescriptor[0].mime = "image/jpg";
fileDescriptor[0].encode64 = true;
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;

EMailSender::Attachments attachs = {3, fileDescriptor};`

by this one: compilation without problem, sending the email BUT no attached files

byte nb=3;
EMailSender::EMailMessage message;
message.subject = "3 Fichiers gpx";
message.message = "Utilisation de MyTracker ";
EMailSender::FileDescriptior fileDescriptor[nb];
byte boucle=3;
String nomfichier;
while ( boucle > 0){
nomfichier = String( "parcours" + String(boucle) + ".gpx");
char __dataFileName[sizeof(nomfichier)];
nomfichier.toCharArray(__dataFileName, sizeof(__dataFileName));
fileDescriptor[boucle].filename = F(__dataFileName);
nomfichier = String( "/" + nomfichier );
__dataFileName[sizeof(nomfichier)];
nomfichier.toCharArray(__dataFileName, sizeof(__dataFileName));
fileDescriptor[boucle].url = F(__dataFileName);
fileDescriptor[boucle].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
fileDescriptor[boucle].mime = MIME_TEXT_PLAIN;
Serial.print(" nomfichier : "); Serial.print(nomfichier);
Serial.print(" boucle : "); Serial.println(boucle );
boucle -- ; }

EMailSender::Attachments attachs = {boucle, fileDescriptor};

Work with Portenta H7 and Exchange Server

I managed to get this to work as per the thread on the arduino forum

https://forum.arduino.cc/t/send-email-via-smtp-with-portenta/1006604/8

The main changes that were required were removing the colon from the end of the HELO command (I had changed it to EHLO via the function call).

String helo = commandHELO + " "String(publicIPDescriptor)"; <--- eliminating the colon at the end of this

I also had to increase the number of iterations to check for
if (this->useEHLO == true) { for (int i = 0; i<=11; i++) awaitSMTPResponse(client); }

However, on this one it is likely better to add a larger number and stop the loop when the first call to the routine takes longer than say 1 second (ie no more left)

JSON link for auto install the library

hi, very nice project.

Is it able to giving the json link for auto library installation with Arduino ?

we could fork and json, but every of your update of pull request would have to pointing back to this master tree.

Can not send email

hello.
please add this function client.setInsecure() in send

EMailSender::Response EMailSender::send(const char* to, EMailMessage &email)
{
WiFiClientSecure client;

client.setInsecure(); <<<<<<<<

Particle.io Argon Support

Hello,

I was wondering what it would take to get this to work on a Particle Argon?

I think I'm having a problem configuring the EMAIL_NETWORK_TYPE correctly, do you have any suggestions?

The Particle Argon uses a Espressif ESP32-D0WD 2.4 GHz Wi-Fi coprocessor.

Best,

Alan

Needs more than 40 seconds to send. Any ideas why?

Serial Monitor:

...............................
Connection: ESTABLISHED
Got IP address: 192.168.0.23
Sending status: 
1
0
Message sent!
Time for sending: 42.47 seconds

My code:
Credentials and mail replaced by "***"

/*
   EMailSender library for Arduino, esp8266 and esp32
   Simple esp8266 Gmail send example

   https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/

*/

#include "Arduino.h"
#include <EMailSender.h>
#include <ESP8266WiFi.h>

const char* ssid = "***";
const char* password = "***";

uint8_t connection_state = 0;
uint16_t reconnect_interval = 2000;

EMailSender emailSend("***", "***", "***", "***", "mail.gmx.net", 465);

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);

  connection_state = WiFiConnect(ssid, password);
  if (!connection_state) // if not connected to WIFI
    Awaits();          // constantly trying to connect

  emailSend.setPublicIpDescriptor("WemosSensor");
  //emailSend.setIsSecure(true);
  emailSend.setEHLOCommand(true);

  EMailSender::EMailMessage message;
  message.mime = MIME_TEXT_PLAIN;
  message.subject = "Soggetto";
  message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";

  uint32_t start = millis();

  EMailSender::Response resp = emailSend.send("***", message);

  Serial.println("Sending status: ");

  Serial.println(resp.status);
  Serial.println(resp.code);
  Serial.println(resp.desc);

  uint32_t end = millis();

  Serial.print(F("Time for sending: "));
  Serial.print((double)(end - start) / 1000, 2);
  Serial.println(F(" seconds"));
}

void loop() {}

I have a small question.

Hello,

So I want to send an email using Raspberry Pi Pico W I tried your examples and it did not work. You are saying it can be used in RP2040 can you explain how?

Thank you in advance

Envoi de données dans le corps du mail

Bonjour, tout d'abord merci pour le travail accompli sur ce code qui fonctionne très bien chez moi. Je poste car je voudrais pouvoir avec ce sketch envoyer des données par mail, c'est à dire dans le corps du mail ou même dans l'entête, je ne sais pas comment faire, quelqu'un peut il m'aider ? cordialement Phil

Compiler warning for redefinition of EMAIL_NETWORK_CLASS

Using PlatformIO and VS Code, compiling for ESP32 (board = lolin32), I always get:

In file included from src/internet.h:8,
                 from src/main.cpp:10:
.pio/libdeps/lolin32/EMailSender/EMailSender.h:302: warning: "EMAIL_NETWORK_CLASS" redefined
   #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS
 
In file included from src/internet.h:8,
                 from src/main.cpp:10:
.pio/libdeps/lolin32/EMailSender/EMailSender.h:182: note: this is the location of the previous definition
 #define EMAIL_NETWORK_CLASS WiFiClient

And if I look at EMailSender.h, I see that both lines 182 and 302 are trying to define EMAIL_NETWORK_CLASS. That is, the compiler has both of those lines displayed in normal (not grayed-out) text.

This is only a WARNING, so my code still compiles, but it's always nice to not have any warnings, especially if it's an easy fix.

timeout with ESP32 and ethernet2

I have tried the ESP32Gmailtest and worked ok with wifi. But I need to send Email through wired LAN. since I have used W5500 in my hardware, I changed these parameters in EmailSendKey.h:

#define DEFAULT_EMAIL_NETWORK_TYPE_ESP32 NETWORK_ETHERNET_2 //NETWORK_ESP32
#define FORCE_DISABLE_SSL

in setup routin, instead of wifi initialize, I have initialized Ethernet as follow:

Ethernet.init(5);
Ethernet.begin(mac, ip, mydns, mygw);

after build and programming the result is:
Sending status:
0
1
Connection Error! SMTP Response TIMEOUT!

could any body help me what additional changes should I make to send Email without Timeout error?
thanks in advance

DistributionList example has incorrect comment

Currenly in DistributionList.ino:
// // Send to 3 different email first to C second to CC and third to CCn
// const char* arrayOfEmail[] = {"@gmail.com", "@yahoo.com", "@hotmail.com"};
// EMailSender::Response resp = emailSend.send(arrayOfEmail, 3, message);

I believe the last line should be:

// EMailSender::Response resp = emailSend.send(arrayOfEmail, 1, 1, 1, message);

Time out

Hi,
Although this seemed to work for a few mails, Now all I get is :

Sending status: 
0
1
SMTP Response TIMEOUT!

Any help would be great!
Thanks for all the work!

EMailSenderEsp32GMailLITTLEFSAttachTest.ino

Hello,

With ESP32 -S2 wemos S2 mini and
EMailSenderEsp32GMailLITTLEFSAttachTest.ino

With
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_LITTLEFS;

'EMAIL_STORAGE_TYPE_LITTLEFS' is not a member of 'EMailSender'

But with
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_LITTLE_FS;

In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook__sources\esp32 s2\EMailSenderEsp32GMailLITTLEFSAttachTest\EMailSenderEsp32GMailLITTLEFSAttachTest.ino:15:
C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\EMailSender/EMailSender.h:222: warning: "EMAIL_NETWORK_CLASS" redefined
#define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS

In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook__sources\esp32 s2\EMailSenderEsp32GMailLITTLEFSAttachTest\EMailSenderEsp32GMailLITTLEFSAttachTest.ino:15:
C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\EMailSender/EMailSender.h:165: note: this is the location of the previous definition
#define EMAIL_NETWORK_CLASS WiFiClient

C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\LittleFS_esp32\src\LITTLEFS.cpp: In member function 'virtual bool LITTLEFSImpl::exists(const char*)':
C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\LittleFS_esp32\src\LITTLEFS.cpp:44:28: error: no matching function for call to 'LITTLEFSImpl::open(const char*&, const char [2])'
File f = open(path, "r");
^
In file included from C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\LittleFS_esp32\src\LITTLEFS.cpp:17:
C:\Users\admin\Desktop\arduino-1.8.18\portable\packages\esp32\hardware\esp32\2.0.2\libraries\FS\src/vfs_api.h:38:17: note: candidate: 'virtual fs::FileImplPtr VFSImpl::open(const char*, const char*, bool)'
FileImplPtr open(const char* path, const char* mode, const bool create) override;
^~~~
C:\Users\admin\Desktop\arduino-1.8.18\portable\packages\esp32\hardware\esp32\2.0.2\libraries\FS\src/vfs_api.h:38:17: note: candidate expects 3 arguments, 2 provided
Plusieurs bibliothèque trouvées pour "SD.h"
Utilisé : C:\Users\admin\Desktop\arduino-1.8.18\portable\packages\esp32\hardware\esp32\2.0.2\libraries\SD
Non utilisé : C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\SD
Plusieurs bibliothèque trouvées pour "WiFi.h"
Utilisé : C:\Users\admin\Desktop\arduino-1.8.18\portable\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi
Non utilisé : C:\Users\admin\Desktop\arduino-1.8.18\portable\sketchbook\libraries\WiFi
exit status 1
Erreur de compilation pour la carte ESP32S2 Dev Module

Happy new year

fr

No output

I've uploaded the code on my esp8266 module, but it doesn't send any email, moreover i can se only this output on the serial monitor:

ets Jan 8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

how can I solve?

Raspberry Pi Pico W

I'm trying to send email from Pico W using this library. But, it is not working. What changes I've to make in order to work. Thanks.

EMailSender using Ethernet Shield

I am trying to use EMailSender using Ethernet Shield but it is not working. I already followed the steps in the documentation but it doesn't work for me.

#include <SPI.h>
#include <Ethernet.h>

#include <EMailSender.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EMailSender emailSend("[email protected]", "password");

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
// while (!Serial) {}

delay(2000);

Serial.println("Starting!");

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure Ethernet using DHCP");
  while(1);
}
Serial.print("IP address ");
Serial.println(Ethernet.localIP());


EMailSender::EMailMessage message;
message.subject = "Soggetto";
message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";

EMailSender::Response resp = emailSend.send("[email protected]", message);

Serial.println("Sending status: ");
 
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);

}
void loop() {
// put your main code here, to run repeatedly:

}

"Unsecure App"?

Hi, I have a question, is there any way to not have to activate the "Unsecure App"?, because if I activate this option, google will automatically deactivate it if it is not used.

My question is if it's possible to prevent google from disabling "App not secure" or if there's another way I don't need to enable it.

Username and password encryption

Thank you for an excellent plugin that worked first try without issues. There is one large issue though.

There does not seem to be support for any encryption that I can see for usernames or passwords.

Anything to protect public repos information would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.