ESP32-Poe-Iso Email Ethernet problem

Started by Partec, April 09, 2020, 06:39:03 PM

Previous topic - Next topic

Partec

Hi,
I want to send an email through Ethernet. I follow the example via wifi and it works perfectly, but if I connect via Ethernet I receive the following message:

Connecting to SMTP server...
SMTP server connected, wait for response...
Error, could not handle SMTP server response
Error sending Email, could not handle SMTP server response

It is a problem with the answer, buy by WiFi is Ok. Can be a library problem?

Board ESP32-POE-ISO rev C
On PlatformIO, with and arduino framework
The code is:

/*
  Rui Santos
  Complete project details at https://randomnerdtutorials.com/esp32-send-email-smtp-server-arduino-ide/
 
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
 
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12

#include <ETH.h>
#include <ESP32Ping.h>
#include <WiFi.h>
#include "time.h"
#include <EEPROM.h>
#include "ESP32_MailClient.h"



// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "MiRouterB3F8";
const char* password = "XXXXXXXXXXXXX";

// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// YOU MUST ENABLE less secure app option https://myaccount.google.com/lesssecureapps?pli=1
#define emailSenderAccount    "partecdeveloper@gmail.com"   
#define emailSenderPassword   "XXXXXXXXXXXXXXX"
#define emailRecipient        "raul@partec.es"
#define smtpServer            "smtp.gmail.com"
#define smtpServerPort        465
#define emailSubject          "ESP32 Test 2"


static bool eth_connected = false;

// The Email Sending data object contains config and data to send
SMTPData smtpData;

// Callback function to get the Email sending status
void sendCallback(SendStatus info);

void WiFiEvent(WiFiEvent_t event){  // Aunque es la libreria WiFi trabaja con el ETH
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      Serial.print(", DNS1: ");
      Serial.print(ETH.dnsIP());

      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case SYSTEM_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default:
      break;
  }
}

void setup(){
  Serial.begin(115200);
  Serial.println();
 
  Serial.print("Connecting");
 
  /*
  //uncomment for WiFi connection
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(200);
  }
  */

  //uncomment for ETH connection
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
  while (eth_connected == false) {
    Serial.print(".");
    delay(200);
  }
 
  Serial.println();
  Serial.println("WiFi o ETH connected.");
  Serial.println();
  Serial.println("Preparing to send email");
  Serial.println();
 
  // Set the SMTP Server Email host, port, account and password
  smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);

  // For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be
  // enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
  //smtpData.setSTARTTLS(true);

  // Set the sender name and Email
  smtpData.setSender("ESP32", emailSenderAccount);

  // Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
  smtpData.setPriority("High");

  // Set the subject
  smtpData.setSubject(emailSubject);

  // Set the message with HTML format
  smtpData.setMessage("<div style=\"color:#2f4468;\"><h1>Hello World!</h1><p>- Sent from ESP32 board</p></div>", true);
  // Set the email message in text format (raw)
  //smtpData.setMessage("Hello World! - Sent from ESP32 board", false);

  // Add recipients, you can add more than one recipient
  smtpData.addRecipient(emailRecipient);
  //smtpData.addRecipient("YOUR_OTHER_RECIPIENT_EMAIL_ADDRESS@example.com");

  smtpData.setSendCallback(sendCallback);

  //Start sending Email, can be set callback function to track the status
  if (!MailClient.sendMail(smtpData))
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());

  //Clear all data from Email object to free memory
  smtpData.empty();
}

void loop() {
 
}

// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
  // Print the current status
  Serial.println(msg.info());

  // Do something when complete
  if (msg.success()) {
    Serial.println("----------------");
  }
}