SMTP with esp8266: again “Could not connect to mail server”

Home Forums esp8266 SMTP with esp8266: again “Could not connect to mail server”

Tagged: 

Viewing 2 reply threads
  • Author
    Posts
    • #27139
      bernard
      Participant

        Sorry all, here I am with a connexion problem several persons got in the past.
        I use an ESP8266 chip paired onboard with an ATMega.
        ESP8266 core lib is 3.0.2.
        EMAIL_NETWORK_CLASS is “WiFiClientSecure”

        I really do not undersand because I’m in a very basic case.
        I did what have to be done to get an App password from Google, but it seems to me it’s not an auth problem. I’m sure of my wifi config because I usually use NTP requests to sync my time on that device same config, together with other https cloud requests. Here is the simple code I tested to sendmail.

        
        #include <ESP8266WiFi.h>
        #include <Arduino.h>
        #include <EMailSender.h>
        #include <EMailSenderKey.h>
        #include <trust_anchors.h>
        
        // wifi stufs
        const char ssid[] = "my wifi name";
        const char pass[] = "aSecret";
        IPAddress local_IP(192, 168, 1, 3);
        IPAddress gateway(192, 168, 1, 1);
        IPAddress subnet(255, 255, 255, 0);
        IPAddress primaryDNS(192, 168, 1, 1);
        
        void setup() {
            Serial.begin(115200);
            delay(1000);
        
            while (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) {
                Serial.println("WiFi.config() Failed, wait 5 secs then retry");
                delay(5000);
            }
            Serial.println("WIFI connected...");
            IPAddress ip = WiFi.localIP();
            Serial.print("My IP Address: ");
            Serial.println(ip);
        
            EMailSender emailSender("my_mail@gmail.com", "google_app_passw");
            const char* arrayOfRecipientsEmail[] = {"anotherMailAddress@me.com"};
            EMailSender::EMailMessage message;
            message.mime = MIME_TEXT_HTML;
            message.subject = "Ciao bello";
            message.message = "Questa è la storia di uno di noi..." ;
        
            Serial.print("Sending mail...");
            EMailSender::Response resp = emailSender.send(arrayOfRecipientsEmail, 1, message);
            Serial.println("Email sending status: ");
            Serial.println(resp.status);
            Serial.println(resp.code);
            Serial.println(resp.desc);
        }
        
        void loop() {
        }
        WIFI connected...
        My IP Address: 192.168.1.3
        Sending mail...miltiple destination and attachments
        Insecure client:0
        MFLN supported: no
        smtp.gmail.com
        465
        Email sending status: 
        0
        2
        Could not connect to mail server

        Thanks for your help.
        Bernard

      • #27147
        bernard
        Participant

          I set debug mode and add these lines in EMailSender.cpp line 514

            if(!client.connect(this->smtp_server, this->smtp_port)) {
          
          	  char buf[256];
          	  client.getLastSSLError(buf,256);
          	  DEBUG_PRINT( "Error:" );
          	  DEBUG_PRINTLN( buf );
          	  response.desc = F("Could not connect to mail server");
          	  response.code = F("2");
          	  response.status = false;
                    ...
          

          to get the real reason of the SMTP connexion fails. What a surprise, I got this:
          “Unable to allocate memory for SSL structures and buffers.”

          I remember then that in the same sketch I was already using a WiFiClientSecure client for https requests. I seems using a different second one is bad.
          So I have changed the EMailSender.cpp to make it re-use the existing one and it works.

          Bernard

        • #27149
          Renzo Mischianti
          Keymaster

            Thanks, Bernard, for your reply.
            Yes, the use of SSL can generate a lot of problems, and esp8266 has a limited quantity of memory with respect to an esp32 and It can happen.
            Bye Renzo

            • #27174
              bernard
              Participant

                hello Renzo,

                unfortunetely re-using WiFiClientSecure client with
                extern WiFiClientSecure client;

                does often the work but not all times. I frequently get ESP reboots, I mean “wdt reset”. These resets come during the client.connect() phase.

                EMailSender::Response response;
                
                  client.flush();  //be sure client is ok
                  client.stop();
                  DEBUG_PRINTLN("start connect to smtp server " + (String)smtp_server + " on port " + (String)this->smtp_port );
                  DEBUG_PRINTLN("ESP getFreeHeap()" + (String)ESP.getFreeHeap());
                  if(!client.connect(this->smtp_server, this->smtp_port)) {
                	  DEBUG_PRINTLN("smtp connexion fails");
                smtp=smtp.gmail.com
                port=465
                MFLN supported: no
                start connect to smtp server smtp.gmail.com on port 465
                ESP getFreeHeap(): 27016
                
                 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
                
                wdt reset
                load 0x4010f000, len 3424, room 16 
                tail 0
                chksum 0x2e
                load 0x3fff20b8, len 40, room 8 
                tail 0
                chksum 0x2b
                csum 0x2b
                v00073200
                ~ld

                Sometime I get an exception report but I unable to analyze/understand it:

                smtp=smtp.gmail.com
                port=465
                MFLN supported: no
                start connect to smtp server smtp.gmail.com on port 465
                ESP getFreeHeap()26040
                
                --------------- CUT HERE FOR EXCEPTION DECODER ---------------
                
                Soft WDT reset
                
                Exception (4):
                epc1=0x4023ca42 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
                
                >>>stack>>>
                
                ctx: sys
                sp: 3ffff540 end: 3fffffb0 offset: 0160
                3ffff6a0:  00000000 c02fc02b c030c02c 00000000  
                3ffff6b0:  00003a98 0004a5e6 3fff19d4 4020b7ac  
                3ffff6c0:  000000db 3fffb00c 3fffa60c 4022e35c  
                3ffff6d0:  00000008 00000001 0001500d 00000000  
                3ffff6e0:  3fffab0c 4022f4b4 3fffa60c 00000000  
                3ffff6f0:  3fffab0c 3fff0f54 3fffa60c 3fff0f54  
                3ffff700:  00000000 00000001 3fff19d4 4020b8bb  
                3ffff710:  00000000 00000001 3fff19d4 4020baa7  
                3ffff720:  00000000 00014fd1 2624dd2f 018449d4  
                3ffff730:  00000000 00000000 00000034 00014fd1  
                3ffff740:  00003a98 3fff180c 3fff19d4 4020a7d7  
                3ffff750:  3fff45ac 0000076a 3ffe864c 4010078e  
                3ffff760:  4020de38 3fff00e8 3ffff780 00000000  
                3ffff770:  000001d1 3fff0f54 3fff19d4 4020bb49  
                3ffff780:  40213fb8 6c66fa8e 40213fb8 6c66fa8e  
                3ffff790:  3ffef9c0 3ffef9c0 3ffeff44 4020d4af  
                3ffff7a0:  00000000 0016001f 00000000 00000000  
                3ffff7b0:  40104263 00040000 00000000 3ffe9a5f  
                3ffff7c0:  3ffe9a60 3ffe83d0 3ffff880 4021cd44  
                3ffff7d0:  00000000 00000002 00000002 00000000  
                3ffff7e0:  00000002 00000002 3f302064 40226f3c  
                3ffff7f0:  00000000 00000752 3ffe864c 4010078e  
                3ffff800:  64e0e37a 00000000 00015180 32000000  
                3ffff810:  00383530 00000000 00015180 00000000  
                3ffff820:  00000014 3fff4594 00000000 40220199  
                3ffff830:  3ffff910 3ffff900 00000010 402201f8  
                3ffff840:  3ffff910 3ffff900 0000000c 402114d0  
                3ffff850:  3ffff8a4 fffffffc 000071bd 00000000  
                3ffff860:  0000a8c0 327071bd 00000000 3fff00e8  
                3ffff870:  00000024 40269e3c 00000000 4020e390  
                3ffff880:  746c696d 656c7069 73656420 616e6974  
                3ffff890:  6e6f6974 646e6120 74746120 6d686361  
                3ffff8a0:  00000000 0016001f 00000000 00000000  
                3ffff8b0:  0037003f 00000000 00000000 0034003f  
                3ffff8c0:  00000000 00000000 002b002f 00000000  
                3ffff8d0:  3ffff9b4 00000020 00000001 3ffe8634  
                3ffff8e0:  00004c84 00000000 00000000 3fff46d4  
                3ffff8f0:  3fff00e8 00000030 00000020 402114d0  
                3ffff900:  3ffe8a34 fffffffc 00000080 3ffff990  
                3ffff910:  00000001 3ffeff44 3ffff9b4 4020dcec  
                3ffff920:  3ffff990 00000000 00000000 4020e3fc  
                3ffff930:  0000004e 3ffeff44 3ffff9b4 4020dd38  
                3ffff940:  00000000 00000000 3ffff9d0 4020f21c  
                3ffff950:  3ffe8634 00000000 3ffe8648 3ffffe38  
                3ffff960:  00000001 00000001 402101be 00000001  
                3ffff970:  00000001 3ffffe38 00000000 40207b92  
                3ffff980:  00000000 00000000 3ffffe38 4020eec1  
                3ffff990:  74786574 616c702f 0a006e69 3fff4434  
                3ffff9a0:  000c000f 80000000 3fff46d4 004e004f  
                3ffff9b0:  81000000 00000000 004e004f 00000000  
                3ffff9c0:  00000000 00000032 00000000 40210200  
                3ffff9d0:  00000000 00000000 00000000 00000000  
                3ffff9e0:  002d002f 00000000 00000000 002c002f  
                3ffff9f0:  00000000 00000000 00000032 40210b60  
                3ffffa00:  3ffffe90 3ffe8e41 3ffffe10 4020376c  
                3ffffa10:  3ffffa38 3ffffa49 3ffffe18 3ffffe38  
                3ffffa20:  3ffef900 3ffffef0 3ffffe28 3ffffe28  
                3ffffa30:  3ffffb20 4020eec1 68737570 616c615f  
                3ffffa40:  61006d72 6d72616c 00726500 63754265  
                3ffffa50:  4670006b 6d725600 63610073 69740074  
                3ffffa60:  0072656d 00707962 0066766f 40209f96  
                3ffffa70:  00001388 00000000 3fff19d4 4020b7d5  
                3ffffa80:  3fffff00 7fc40000 00000000 00000000  
                3ffffa90:  00000010 00000000 0000c1ba 00000001  
                3ffffaa0:  00000002 fffffffc 00000000 3ffffefc  
                3ffffab0:  3fffff08 00000020 3fffa404 3fff0280  
                3ffffac0:  3ffffef0 00000000 3fff19d4 4020bbbb  
                3ffffad0:  00000066 3ffef9c0 3fffff38 4020851a  
                3ffffae0:  3ffe944a 3ffffefc 3ffe9440 3ffffef0  
                3ffffaf0:  7570227b 695f6873 3a22766e 6e69227b  
                3ffffb00:  63615f76 65776f70 223a2272 2e353739  
                3ffffb10:  222c2230 5f766e69 74617473 3a227375  
                3ffffb20:  32303120 6e69222c 72705f76 664f646f  
                3ffffb30:  44656854 3a227961 352e3422 69222c22  
                3ffffb40:  00000002 00000000 00000020 401001a4  
                3ffffb50:  40102505 63007d7d 00000002 401020d4  
                3ffffb60:  3ffea162 40105353 3ffed830 7961646f  
                3ffffb70:  00000001 4010452e 3ffee328 61746f74  
                3ffffb80:  4010499f 2e343732 66222c34 69646565  
                3ffffb90:  776f706e 3a227265 2c302e30 65656622  
                3ffffba0:  40104467 00000017 00000002 00040000  
                3ffffbb0:  00002200 65656d75 6772656e 303a2279  
                3ffffbc0:  000005e0 00000000 40104171 3ffee2e0  
                3ffffbd0:  0000003c 00000000 22636f73 000000fc  
                3ffffbe0:  0000001c 00000001 401052b9 3ffee2e0  
                3ffffbf0:  00000005 00000000 00000020 401001a4  
                3ffffc00:  3ffeda10 00000000 00000005 401020d4  
                3ffffc10:  3ffea165 4010536b 3ffedba0 40105c05  
                3ffffc20:  40102c5f 3ffedba0 3ffee2e0 401001a4  
                3ffffc30:  00000069 050e1b06 3ffee4c0 40102e3c  
                3ffffc40:  3ffeaa1c 00000000 00000000 00040000  
                3ffffc50:  00000069 00000000 401032f6 000000fd  
                3ffffc60:  00003bf8 0000077f 3ffe864c 4010078e  
                3ffffc70:  00000005 00000000 00000020 0000077f  
                3ffffc80:  3fff4654 00000005 3ffe864c 40100d42  
                3ffffc90:  00000020 00000020 00000014 00000020  
                3ffffca0:  3ffee2b0 3ffedba0 3ffee328 3fff4844  
                3ffffcb0:  0000000b 00000010 00000020 00000001  
                3ffffcc0:  00000010 00000020 3ffffdac 4020edeb  
                3ffffcd0:  0000000f 401047ed 00000002 401020d4  
                3ffffce0:  3ffea162 40105353 3ffed8d0 00000001  
                3ffffcf0:  00000010 00000001 3ffffdac 4020ee7f  
                3ffffd00:  0000001a 00000001 3ffffdac 4020f21c  
                3ffffd10:  3fff4844 3ffffd40 00000002 3fffc278  
                3ffffd20:  40104467 00000016 00000002 00000019  
                3ffffd30:  0000001a 3ffffda0 3ffffdac 4020f366  
                3ffffd40:  4010337d 00000001 3ffffda0 4020f21c  
                3ffffd50:  00003ec8 000007d9 3ffe864c 4010078e  
                3ffffd60:  30307830 2c9f0300 4000050c 3fff48fc  
                3ffffd70:  3ffffed8 00000020 3fff4924 40100adc  
                3ffffd80:  402051b8 ffffffff 3ffffda0 4020ed41  
                3ffffd90:  3ffffed8 ffffffff ffffffff 40205da4  
                3ffffda0:  00000000 001a001f 00000000 00000000  
                3ffffdb0:  001a001f 00000000 3ffe864c 4010078e  
                3ffffdc0:  3fff48f0 00000030 00000020 0000001a  
                3ffffdd0:  3fff46d4 00000020 3fff46d4 00000000  
                3ffffde0:  3ffffe40 00000000 3ffffed8 402046fa  
                3ffffdf0:  3ffffe04 3ffffe00 00000020 3ffffe9c  
                3ffffe00:  3fff4ba4 00000020 00000020 3fff0280  
                3ffffe10:  3fff4ba4 00000020 00000001 00000000  
                3ffffe20:  00004b88 3ffffa43 3ffffe18 3ffffe18  
                3ffffe30:  000000a0 3ffffa38 3fff4894 0021002f  
                3ffffe40:  80000000 3ffe8e46 3ffffa10 3ffe8e41  
                3ffffe50:  3fff4ba4 0000001a 3ffffe90 4020ee7f  
                3ffffe60:  00000000 0000001a 3ffffe90 4020eec1  
                3ffffe70:  00000018 3fff4ba4 3ffffe90 3fff0280  
                3ffffe80:  00000018 00000001 3ffef8b0 402038c3  
                3ffffe90:  3fff486c 001a001f 80000000 3fff4ba4  
                3ffffea0:  001a001f 80000000 00000000 3fff0280  
                3ffffeb0:  3ffef908 00000001 3fff421c 40204089  
                3ffffec0:  00000000 3ffef8e4 3ffef8b0 40205e20  
                3ffffed0:  3fffff28 00000000 00000000 001a001f  
                3ffffee0:  00000000 00000000 00000000 00000000  
                3ffffef0:  00000000 3ffe0079 00000000 00000000  
                3fffff00:  00000000 00000000 00000000 0022002f  
                3fffff10:  00000000 0000007b 3ffef8c4 4020c4f4  
                3fffff20:  00000000 00000001 00000000 00000000  
                3fffff30:  00000000 00000000 3ffef8b0 3fff0280  
                3fffff40:  3ffefa04 3ffef8e4 3ffef8b0 40206c22  
                3fffff50:  40213d24 00000000 00001388 00000001  
                3fffff60:  00000000 00000000 3fff4b6c 00000000  
                3fffff70:  3fff0b94 40209b90 0002bf20 3fff0280  
                3fffff80:  3ffefa04 3fff00e8 0002bf20 40206daa  
                3fffff90:  4020de38 3ffe8a32 3fff00e8 3fff0280  
                3fffffa0:  3fffdad0 00000000 3fff0254 3fff0280  
                <<<stack<<<
                
                --------------- CUT HERE FOR EXCEPTION DECODER ---------------
                
                 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
                
                wdt reset
                load 0x4010f000, len 3424, room 16 
                tail 0
                chksum 0x2e
                load 0x3fff20b8, len 40, room 8 
                tail 0
                chksum 0x2b
                csum 0x2b
                v00073200
                ~ld
                
          Viewing 2 reply threads
          • You must be logged in to reply to this topic.
          Exit mobile version