Help on understanding example sends mail via Ethernet

Hello, I’m desperately trying to send mail from my Arduino Mega via an Ethernet shield.

To start, I unsuccessfully tried the example provided in the library, here is the code:

I can’t send an email even without an attachment …

I have a doubt about what to put in the function:
EMailSender emailSend (email_login, email_password, email_from, smtp_server, smtp_port);

I put this kind of information (is it in base 64 as in another example or in ASCII or …) Thank you

/*
 * EMailSender library for Arduino, esp8266 and esp32
 * Arduino Mega and UIPEthernet send example with attach
 * this example is not tested for all, I can't find a provider
 * that manage attach without SSL and TLS
 *
 * Pay attention you must set in the library
 * #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO 	NETWORK_ENC28J60
 * for UIPEthernet
 *
 * #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO 	NETWORK_W5100
 * for standard Ethernet

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

#include "Arduino.h"
#include <SPI.h>
#include <UIPEthernet.h>
#include <SD.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 };

const char* email_login= "rtl21.gin@wanadoo.fr";    or base 64?
const char* email_password= "RZy28tb"; or base 64?
const char* email_from="rde.mduin@wanadoo.fr";
const char* smtp_server="smtp.orange.fr";
uint16_t smtp_port =25;
EMailSender emailSend (email_login, email_password,  email_from,  smtp_server,  smtp_port);
Sd2Card card;
#define  pinCS_SD  4                              
#define  pinCS_ETH  10

void printDirectory(File dir, int numTabs);

//The setup function is called once at startup of the sketch
void setup()
{
    Serial.begin(115200);
    pinMode(53, OUTPUT);              //Arduino mega
    delay(2000);

    Serial.println("Starting!");

    Serial.print("Initializing SD card...");

    if (!card.init(SPI_HALF_SPEED, pinCS_SD)) {
      Serial.println("initialization failed!");
      return;
    } else [Serial.println("initialization done.");}

    Ethernet.init(pinCS_ETH);

    File root = SD.open("/");

    printDirectory(root, 0);

    Serial.println("done!");


    // 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
io bene.
www.mischianti.org";
    message.mime = MIME_TEXT_PLAIN;



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



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

    EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message, attachs);

    Serial.println("Sending status: ");

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

    File root2 = SD.open("/");

    printDirectory(root2, 0);

    Serial.println("done!");
    SD.end();
}

void loop()
{

}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

And in addition when compiling this example I get warning messages (even if it compiles and the program runs … bad but runs anyway)
see next post for alert codes (no more space in the 1st)

Thanks a lot for any help!

here is also some of the compilation alerts (not enough room in the post once again ...)
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/mempool_conf.h:5:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/mempool.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/Enc28J60Network.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/UIPEthernet.h:35,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\examples\EMailSenderArduinoMegaUIPSDAttachTest\EMailSenderArduinoMegaUIPSDAttachTest.ino:23:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/UIPClient.h:37:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/UIPEthernet.h:41,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\examples\EMailSenderArduinoMegaUIPSDAttachTest\EMailSenderArduinoMegaUIPSDAttachTest.ino:23:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\examples\EMailSenderArduinoMegaUIPSDAttachTest\EMailSenderArduinoMegaUIPSDAttachTest.ino:33:99: warning: invalid conversion from 'const char*' to 'uint16_t {aka unsigned int}' [-fpermissive]
 EMailSender emailSend("<LOGIN>", "<PASSWD>", "<EMAIL-FROM>", "<SMTP-SERVER>", "<SMTP-SERVER-PORT>");
                                                                                                   ^
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\examples\EMailSenderArduinoMegaUIPSDAttachTest\EMailSenderArduinoMegaUIPSDAttachTest.ino:26:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender/EMailSender.h:224:2: note:   initializing argument 5 of 'EMailSender::EMailSender(const char*, const char*, const char*, const char*, uint16_t)'
  EMailSender(const char* email_login, const char* email_password, const char* email_from, const char* smtp_server, uint16_t smtp_port);
  ^~~~~~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\Dhcp.cpp:6:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\Dhcp.cpp:17:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\Dns.cpp:5:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\UIPClient.cpp:19:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\UIPClient.cpp:23:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/mempool_conf.h:5:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/mempool.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/Enc28J60Network.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\UIPEthernet.h:35,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\UIPEthernet.cpp:27:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~

In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool_conf.h:5:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool.cpp:20:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool_conf.h:5:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\Enc28J60Network.h:28,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\Enc28J60Network.cpp:25:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\mempool.cpp:22:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\Enc28J60Network.cpp:34:0:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet\utility\logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/uipopt.h:97:4: warning: #warning "Endianness configured automaticaly." [-Wcpp]
   #warning "Endianness configured automaticaly."
    ^~~~~~~
In file included from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/UIPClient.h:37:0,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/UIPEthernet.h:41,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/Ethernet.h:1,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\EMailSender.h:141,
                 from C:\Users\PC bureau Gilles\Documents\Arduino\libraries\EMailSender\EMailSender.cpp:35:
C:\Users\PC bureau Gilles\Documents\Arduino\libraries\UIPEthernet/utility/logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp]
 #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
  ^~~~~~~

Thanks

I also tested this example which works well, but I cannot modify it to attach a CSV file located on the micro Sd of the Ethernet shield …

#include <EMailSender.h>
#include <SPI.h>
#include <Ethernet.h>
#include "Smtp_Service.h"
//  base 64  https://www.convertstring.com/fr/EncodeDecode/Base64Decode

 
const unsigned int SMTP_PORT = 25;
 
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x81, 0xB2 };
byte smtp_server[] = {193,252,22,84};     // or {80,12,242,10}; 

SmtpService smtp_service(smtp_server, SMTP_PORT);
 
char incString[250];
 
String domain =   "smtp.orange.fr";
String login =    "facfefg0+I=";         //login on 64 base 
String password = "Zm----A5";      //Password on 64 base 

IPAddress ip(192,168,1,143);  // Default IP
 
 
 
Email courrier;
 
void setup()
{
  Serial.begin(9600);
   
  pinMode(53, OUTPUT);     // pin 53 on Mega
  
   Ethernet.init(10);                     // Start Ethernet on pin 10
   
   char erreur = 0;
Serial.println(F("Init"));

  erreur = Ethernet.begin(mac);

  if (erreur == 0) {
    Serial.println(F(" fix IP..."));     
    Ethernet.begin(mac, ip);                           
    Serial.println(Ethernet.localIP());                
    
                  }
                  
  Serial.println(F("Init..."));
 
  delay(1000);                                      
  Serial.println(Ethernet.localIP());
  
   
   Serial.setTimeout(500000);   
   delay(1000);  
    
   courrier.setDomain(domain);
   courrier.setLogin(login);
   courrier.setPassword(password);
    
   courrier.setFrom("rolaxxyx.xxxin@wanadoo.fr");
   courrier.setTo("roxxx.xxxngin@wanadoo.fr");
   courrier.setCc("gies.xxxxxin@gmail.com");
   courrier.setSubject("Arduino Mail Test");
   courrier.setBody("TEST2!!");

Serial.println(F("Push S to serial monitor for send email:"));

}
 
 
 
void loop()
{
  //Serial.println(F("On est dans la boucle"));
  
  if (Serial.available() > 0) {
    byte inByte = Serial.read();
    if (inByte == 'S')
    {
      smtp_service.send_email(courrier); 
    }
   
  delay(1000);
                             }
}

Smtp_service.h:

#ifndef __SMTP_SERVICE__H_
#define __SMTP_SERVICE__H_

#include "email.h"


class SmtpService
{
  byte*    _smtp_server;
  unsigned int _port;
 
  void read_response(Client& client)
  {
    delay(5000);
    while(client.available())
    {
      const char c = client.read();
      Serial.print(c);
    }
  }
 
  void send_line(Client& client, String line)
  {
    const unsigned int MAX_LINE = 256;
    char buffer[MAX_LINE];
    line.toCharArray(buffer, MAX_LINE);
    Serial.println(buffer);
    client.println(buffer);
    read_response(client);
  }
 
  public:
 
  SmtpService(
  byte*   smtp_server,
  const unsigned int port) : _smtp_server(smtp_server),
                             _port(port) {}
                             
  void send_email (const Email& email)
  {
    EthernetClient client;
    Serial.print(F("Connexion..."));
   
    if(!client.connect(_smtp_server, _port))
    {
      Serial.println(F("Echec connexion."));
    }
    else
    {     //NE PAS TRADUIRE PLUS SINON NE FONCTIONNE PAS!
      Serial.println(F("Connecté."));                             
      read_response(client);
      send_line(client, String("ehlo ") + email.getDomain());    
      send_line(client, String("AUTH LOGIN"));
      send_line(client, email.getLogin());
      send_line(client, email.getPassword());
      send_line(client, String("mail from: <") + email.getFrom() + String(">"));
      send_line(client, String("rcpt to: <") + email.getTo() + String(">"));
      send_line(client, String("rcpt to: <") + email.getCc() + String(">"));
      send_line(client, String("data"));
      send_line(client, String("from: ") + email.getFrom());
      send_line(client, String("to: ") + email.getTo());
      send_line(client, String("subject: ") + email.getSubject());
      send_line(client, String(""));                                            
      send_line(client, email.getBody());                                       
      send_line(client, String("."));                                            
      send_line(client, String("quit"));                                      
      client.println("Disconnecting.");
      client.stop();
    }
  }
};       
   
#endif

email.h :

#ifndef __EMAIL__H_
#define __EMAIL__H_

class Email
{
  String _domain, _login, _password, _from, _to, _cc, _subject, _body;
 
  public:
 
  Email(
  const String& domain = "",
  const String& login = "",
  const String& password = "",
  const String& from = "",
  const String& to = "",
  const String& cc = "",
  const String& subject = "",
  const String& body = ""
  ) : _domain(domain), _login(login), _password(password),  _from(from), _to(to), _cc(cc), _subject(subject), _body(body) {}  //
   
  const String& getDomain()   const { return _domain;     }
  const String& getLogin()    const { return _login;      }
  const String& getPassword() const { return _password;   }
  const String& getFrom()     const { return _from;       }
  const String& getTo()       const { return _to;         }
  const String& getCc()       const { return _cc;         }
  const String& getSubject()  const { return _subject;    }
  const String& getBody()     const { return _body;       }
 
  void setDomain( const String domain)     { _domain = domain;    }
  void setLogin( const String login)       { _login = login;      }
  void setPassword( const String password) { _password= password; }
  void setFrom( const String from)         { _from = from;        }
  void setTo( const String to)             { _to = to;            }
  void setCc( const String cc)             { _cc = cc;            }
  void setSubject( const String subject)   { _subject = subject;  }
  void setBody( const String body)         { _body = body;        }
};

#endif

If anyone knows how (and if it’s possible) to modify it to attach a csv file …

Thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.