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

Compiler warning for redefinition of EMAIL_NETWORK_CLASS #35

Closed ba58smith closed 11 months ago

ba58smith commented 1 year ago

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.

xreef commented 1 year ago

Hi @ba58smith, I know that when I have some time, I will fix It in the future, but not soon. Thanks Renzo

ba58smith commented 1 year ago

Renzo,

Everywhere EMAIL_NETWORK_SSL_CLASS is defined, EMAIL_NETWORK_CLASS is also defined, like below, for NETWORK_ESP32:

#elif(EMAIL_NETWORK_TYPE == NETWORK_ESP32)

#include <WiFi.h>
#include <WiFiClientSecure.h>
#define EMAIL_NETWORK_CLASS WiFiClient
#define EMAIL_NETWORK_SSL_CLASS WiFiClientSecure
#define EMAIL_NETWORK_SERVER_CLASS WiFiServer

If I change every one of those to something like this...

#elif(EMAIL_NETWORK_TYPE == NETWORK_ESP32)

#include <WiFi.h>
#include <WiFiClientSecure.h>
#ifndef FORCE_DISABLE_SSL
    #define EMAIL_NETWORK_CLASS WiFiClientSecure
#else
    #define EMAIL_NETWORK_CLASS WiFiClient
#endif
#define EMAIL_NETWORK_SSL_CLASS WiFiClientSecure
#define EMAIL_NETWORK_SERVER_CLASS WiFiServer

...then I think I can remove the redefinition of EMAIL_NETWORK_CLASS (lines 304 to 308, below):

#ifdef EMAIL_NETWORK_SSL_CLASS
    #ifndef FORCE_DISABLE_SSL
        #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS
    #endif
#endif

There may be a more elegant way of solving the issue, but I'm not seeing it. If you like my suggestion, I'll make a PR for it - however, I have no way to test it with all of the different types of processors.

Andy2051 commented 1 year ago

Just to add I have the same problem, compiling with arduino 1.8.19 for an esp8266:

/home/andy/Arduino/libraries/EMailSender-master/EMailSender.h:222: warning: EMAIL_NETWORK_CLASS" redefined
  222 | #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS
      | 
In file included from /home/andy/Arduino/oilsensor7/email.cpp:16:
/home/andy/Arduino/libraries/EMailSender-master/EMailSender.h:131: note: this is the location of the previous definition
  131 | #define EMAIL_NETWORK_CLASS WiFiClient
Patriboom commented 11 months ago

The upper solution (Andy2051) works for me. I updated the [...]/libraries/EMailSender/EMailSender.h according to what Andy2051 wrote.

libraries/EMailSender/EMailSender.h file lines 189 to 200 go like this:

#elif(EMAIL_NETWORK_TYPE == NETWORK_ESP32)

#include <WiFi.h>
#include <WiFiClientSecure.h>
#ifndef FORCE_DISABLE_SSL
    #define EMAIL_NETWORK_CLASS WiFiClientSecure
#else
    #define EMAIL_NETWORK_CLASS WiFiClient
#endif
#define EMAIL_NETWORK_SSL_CLASS WiFiClientSecure
#define EMAIL_NETWORK_SERVER_CLASS WiFiServer

and lines 326 to 332 :

#ifdef EMAIL_NETWORK_SSL_CLASS
    #ifndef FORCE_DISABLE_SSL
        #define EMAIL_NETWORK_CLASS WiFiClientSecure
    #else
        #define EMAIL_NETWORK_CLASS WiFiClient
    #endif
#endif
xreef commented 11 months ago

Thanks to all, I create a new release soon.