Arduino Uno Wifi Rev2 Could not connect to mail server

Home Forums Arduino Arduino Uno Wifi Rev2 Could not connect to mail server

Viewing 18 reply threads
  • Author
    Posts
    • #16507
      r0vert
      Participant

        Hello, I’m trying to use an Arduino Uno Wifi Rev2 Board with a Ublox W102 wifi/bluetooth module to send emails. However, whenever I try to send an email, the board connects to wifi but says “0 2 Could not connect to mail server.”

        So far, I’ve tried uploading the google.com443 certificate, set the gmail account to allow for less secure app access, enabled IMAP access from the gmail account, and connecting to my phone’s hotspot to check if something in the wifi was blocking it.

        Why is it still not connecting to the mail server? Any help would be appreciated!

        
        #include "Arduino.h"
        #include <EMailSender.h>
        #include <WiFiNINA.h>
        
        uint8_t connection_state = 0;
        uint16_t reconnect_interval = 10000;
        
        const char *ssid = "WiFi SSID";
        const char *password = "WiFi Password";
        
        EMailSender emailSend("Sender email (That has less security settings on)",
        		"Sender email password");
        
        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
        
        	EMailSender::EMailMessage message;
        	message.subject = "Email";
        	message.message = "Email Sent!";
        
        	EMailSender::Response resp = emailSend.send("Recipient email account",
        			message);
        
        	Serial.println("Sending status: ");
        
        	Serial.println(resp.status);
        	Serial.println(resp.code);
        	Serial.println(resp.desc);
        	delay(1000);
        
        }
        
        void loop() {
        
        }
        
        
      • #16516
        Renzo Mischianti
        Keymaster

          Hi r0vert,
          I retry to send message with my MKR 1010 WiFi and I send email without problem after add google.com to this example
          the only difference is that I generate an application password like described here.
          Bye Renzo

        • #16518
          r0vert
          Participant

            Hi Renzo,

            I created an application password like you said and replaced the sender gmail account’s password with it in the code, but I’m still seeing error code 2. I also tried reuploading the google.com certificate.

            Is it because I’m using a W102 wifi module or should this library work for any board compatible with WiFiNINA?

          • #16519
            Renzo Mischianti
            Keymaster

              Hi r0vert,
              theoretically It’s the same, but I write to Arduino to have more info, I write here when they give me a response.
              Bye Renzo

            • #16565
              r0vert
              Participant

                Hi Renzo,

                I’ve been fiddling around with the Arduino and found that the wifi board is able to ping smtp.gmail.com and its port 465. Since my app password settings says that the password hasn’t been used, does this mean that the problem has to do with the logging in?

                Also, for the gmail account being used for sending the emails, is there any other specifications it needs or can it just be any gmail account with less secure access on and app password?

              • #16566
                Renzo Mischianti
                Keymaster

                  Hi,
                  arduino answer me, and the wifi Nina is the same.
                  So there aren’t additional problem respect my mkr 1010 that work with the library.

                  Can you write the exact code with xxx on password and other data without change anything else.. ( same breaket and “)

                  Bye Renzo

                • #16567
                  r0vert
                  Participant
                    
                    #include "Arduino.h"
                    #include <EMailSender.h>
                    #include <WiFiNINA.h>
                    
                    uint8_t connection_state = 0;
                    uint16_t reconnect_interval = 10000;
                    
                    const char *ssid = "Wifi network";
                    const char *password = "Wifi password";
                    uint16_t smtpport = 465;
                    EMailSender emailSend("finnabouttacatchsomerats@gmail.com", "xxxxxxxxxxxxxxxx");
                    
                    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
                    
                    	EMailSender::EMailMessage message;
                    	message.subject = "Email";
                    	message.message = "Email Sent!";
                    
                    	EMailSender::Response resp = emailSend.send("ReceivingEmail@gmail.com",
                    			message);
                    
                    	Serial.println("Sending status: ");
                    
                    	Serial.println(resp.status);
                    	Serial.println(resp.code);
                    	Serial.println(resp.desc);
                    	delay(2000);
                    
                    	 
                    
                    }
                    
                    void loop() {
                    
                    }
                    
                    
                  • #16568
                    r0vert
                    Participant

                      I think that this is the same code that I uploaded before, so if the code worked for you does that mean there’s something wrong with the google account/board?

                      • #16569
                        Renzo Mischianti
                        Keymaster

                          Hi r0vert,
                          I try your sketch and It’s work without problem, I think there is some wrong in your network or your gmail account permission.
                          Try to enable debug on library and send me the result.
                          Bye Renzo

                        • #16572
                          r0vert
                          Participant

                            Connecting to WiFi

                            Connection: ESTABLISHED
                            Got IP address: 10.192.42.23
                            ONLY ONE RECIPIENTmiltiple destination and attachments
                            Insecure client:0
                            smtp.gmail.com
                            465
                            Sending status:
                            0
                            2
                            Could not connect to mail server

                        • #16573
                          r0vert
                          Participant

                            Hi Renzo,

                            I have been able to successfully connect to my phone’s hotspot but it still doesn’t connect to the mail servers, although my phone is connected to the same wifi as the one I’ve been using. If the Wifi network is blocking it, would it still be blocked on the hotspot?

                            If not, would that narrow it down to the google account? I followed the instructions shown for creating the 2-step verification and application password.

                          • #16575
                            Renzo Mischianti
                            Keymaster

                              Hi,
                              the debug message say to us that the micro controller can’t communicate with google, so (if not work with hot spot also) probably there is a problem with the certificate you add to the device.

                              Try to update firmware and the add google.com to the list and request to upload the certificate with the button in the bottom of popup.

                              Bye Renzo

                            • #16576
                              r0vert
                              Participant

                                When I upload the google.com certificate, the popup says that it was successfully downloaded. Not sure if this is supposed to happen, but afterwards my device can’t connect to the internet until I unplug and replug it back in after uploading the certificate. If it says that it was successfully put on the device, is it there indefinitely?

                              • #16577
                                Renzo Mischianti
                                Keymaster

                                  I think It’s permanent, but to be sure try to re-upload the NINA firmware from arduino ide and re-upload the certificate.
                                  Bye Renzo

                                • #16578
                                  r0vert
                                  Participant

                                    Hi Renzo,

                                    I tried uninstalling and reinstalling the WiFiNINA library and reuploading the certificate, but it still gives me the error code 2. I also tried to download the most recent version of WiFiNINA, but to no avail. What else could be wrong with it?

                                     

                                    • #17163
                                      shaunybean
                                      Participant

                                        Hi,

                                        I am also having the EXACT same issue (even the part where you have to power cycle the Arduino after firmware install to get it to connect to the network)

                                        I have tried all the same steps as you and I still cannot connect to the server – did you make any progress?

                                    • #16581
                                      Renzo Mischianti
                                      Keymaster

                                        Hi r0vert,
                                        sorry but the problem can be your network or the certificate, I don’t know how to help you better.
                                        Bye Renzo

                                        • #17167
                                          Renzo Mischianti
                                          Keymaster

                                            Hi check the last post and tell me if you do that configuration.
                                            Bye Renzo

                                          • #17169
                                            shaunybean
                                            Participant

                                              Hi Renzo

                                              Thank you – I swapped out this block for the one in your last post. Unfortunately I still get the same error.

                                              Regards

                                              Shaun

                                          • #16607
                                            r0vert
                                            Participant

                                              Hi Renzo,

                                              It’s all good, I’ll keep trying to figure it out. Thank you so much for your time and help!

                                            • #16970
                                              Devina

                                                Hi Renzo,

                                                I’ve the same problem with the same hardware. Everything else is different (my network, my google acc…). I develop esp8266 as well, but there your code is working fine. I think the problem is around WiFiNINA :-(.

                                              • #16971
                                                Renzo Mischianti
                                                Keymaster

                                                  Mmmm… It’s very strange, Arduino had told me that WiFiNINA of my MKR 1010 It’s the same of Arduino Uno Wifi Rev2, but now I’m quiete sure that It isn’t true.
                                                  I try to re-write to It and I put the answer here.
                                                  Bye Renzo

                                                  • #17166
                                                    shaunybean
                                                    Participant

                                                      Could it be to do with the version number of the WiFiNINA ? Do you know what version you last had working?

                                                    • #17170
                                                      Renzo Mischianti
                                                      Keymaster

                                                        Hi,
                                                        In my case, It works with all versions of WiFiNINA, updated every time.
                                                        Check the configuration on the last post
                                                        And give me feedback.
                                                        Thanks Renzo

                                                      • #17171
                                                        shaunybean
                                                        Participant

                                                          Hi Renzo,

                                                          I swapped out the block of code and I am unfortunately still getting the same error. I feel like it could be a setting within google, but I followed the procedure and I do not think I missed any steps. I am using the app password.

                                                          Regards

                                                          Shaun

                                                        • #17192
                                                          shaunybean
                                                          Participant

                                                            Let me know if I can help do any more debugging – I am happy to go onto a zoom or anything if that can help?

                                                            Regards

                                                            Shaun

                                                        • #16972
                                                          Renzo Mischianti
                                                          Keymaster

                                                            Hi all,
                                                            can you send me the configuration of EMailSenderKey.h

                                                            You must have something like this

                                                            
                                                            #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP8266
                                                              #define DEFAULT_EMAIL_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
                                                              #define DEFAULT_INTERNAL_ESP8266_STORAGE STORAGE_SPIFFS
                                                            #endif
                                                            #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP32
                                                              #define DEFAULT_EMAIL_NETWORK_TYPE_ESP32 NETWORK_ESP32
                                                              #define DEFAULT_INTERNAL_ESP32_STORAGE STORAGE_SPIFFS
                                                            #endif
                                                            #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO
                                                              #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_WiFiNINA // substitute from the default config NETWORK_W5100
                                                            #endif
                                                            #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO_SAMD
                                                              #define DEFAULT_EMAIL_NETWORK_TYPE_SAMD NETWORK_WiFiNINA
                                                            #endif
                                                            

                                                            UNO WiFi It isn’t a SAMD device It’s an ATMEGA and you must select backward UNO compatibility.

                                                            Please test It, I don’t have the board, but I hope that It’s work.

                                                            Bye Renzo

                                                            • #17164
                                                              shaunybean
                                                              Participant

                                                                Hi Renzo,

                                                                I didnt change anything in the EMailSenderKey apart from the debug, mine looks like this:

                                                                /*
                                                                * EMail Sender Arduino, esp8266 and esp32 library to send email
                                                                *
                                                                * AUTHOR: Renzo Mischianti
                                                                * VERSION: 2.3.0
                                                                *
                                                                * http://mischianti.org/
                                                                *
                                                                * The MIT License (MIT)
                                                                *
                                                                * Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved.
                                                                *
                                                                * You may copy, alter and reuse this code in any way you like, but please leave
                                                                * reference to www.mischianti.org in your comments if you redistribute this code.
                                                                *
                                                                * Permission is hereby granted, free of charge, to any person obtaining a copy
                                                                * of this software and associated documentation files (the "Software"), to deal
                                                                * in the Software without restriction, including without limitation the rights
                                                                * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                                                                * copies of the Software, and to permit persons to whom the Software is
                                                                * furnished to do so, subject to the following conditions:
                                                                *
                                                                * The above copyright notice and this permission notice shall be included in
                                                                * all copies or substantial portions of the Software.
                                                                *
                                                                * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                                                                * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                                                                * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                                                                * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                                                                * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                                                                * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
                                                                * THE SOFTWARE.
                                                                */
                                                                #ifndef EMailSenderKey_h
                                                                #define EMailSenderKey_h

                                                                // Uncomment if you use esp8266 core <= 2.4.2
                                                                //#define ARDUINO_ESP8266_RELEASE_2_4_2

                                                                #define ENABLE_ATTACHMENTS

                                                                // Uncomment to enable printing out nice debug messages.
                                                                #define EMAIL_SENDER_DEBUG

                                                                // Define where debug output will be printed.
                                                                #define DEBUG_PRINTER Serial

                                                                #define STORAGE_SPIFFS (0)
                                                                #define STORAGE_LITTLEFS (1)
                                                                #define STORAGE_FFAT (2)

                                                                #define NETWORK_ESP8266_ASYNC (0)
                                                                #define NETWORK_ESP8266 (1)
                                                                #define NETWORK_ESP8266_242 (6)
                                                                #define NETWORK_W5100 (2)
                                                                #define NETWORK_ENC28J60 (3)
                                                                #define NETWORK_ESP32 (4)
                                                                #define NETWORK_ESP32_ETH (5)
                                                                #define NETWORK_WiFiNINA (7)

                                                                #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP8266
                                                                #define DEFAULT_EMAIL_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
                                                                #define DEFAULT_INTERNAL_ESP8266_STORAGE STORAGE_SPIFFS
                                                                #endif
                                                                #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP32
                                                                #define DEFAULT_EMAIL_NETWORK_TYPE_ESP32 NETWORK_ESP32
                                                                #define DEFAULT_INTERNAL_ESP32_STORAGE STORAGE_SPIFFS
                                                                #endif
                                                                #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO
                                                                #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100
                                                                #endif
                                                                #ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO_SAMD
                                                                #define DEFAULT_EMAIL_NETWORK_TYPE_SAMD NETWORK_WiFiNINA
                                                                #endif

                                                                #define SD_CS_PIN 4

                                                                //#define STORAGE_INTERNAL_FORCE_DISABLE
                                                                //#define STORAGE_SD_FORCE_DISABLE

                                                                #endif

                                                                I am using a Arduino Nano 33 IoT

                                                                 

                                                            • #17196
                                                              shaunybean
                                                              Participant

                                                                OK – I think I found a fix – for at least me anyway, I noticed something on this site:

                                                                https://forum.arduino.cc/t/solved-http-ssl-post-via-wifinina-uno-wifi-r2-open-tesla-model-3-charge-port/661743

                                                                This bit:

                                                                • Upload “Firmware Updater” sketch to Arduino (Examples->WifiNINA->tools->Firmware Uploader)
                                                                • From IDE menu, Tools-> Wifi 101/ WifiNINA Firmware Updater
                                                                • In Updater, click “Add domain”, then copy and paste in the server which you want to connect to, click OK
                                                                • Previous step tends to make wifi module not work, to fix: Click Update Firmware (takes a while).

                                                                So I tried that way round, basically re-uploading the firmware after adding certificate….and now it works?!?!

                                                                • #17200
                                                                  Renzo Mischianti
                                                                  Keymaster

                                                                    So I tried that way round, basically re-uploading the firmware after adding certificate….and now it works?!?!

                                                                    I await your answer… does it work ??? 😀

                                                                    Thanks Renzo

                                                                  • #17203
                                                                    shaunybean
                                                                    Participant

                                                                      Yes sir, it works now – it seems you have to upload firmware, then add the google.com certificate, and then re-upload the firmware….there must be a bug somewhere?

                                                                    • #17205
                                                                      Renzo Mischianti
                                                                      Keymaster

                                                                        Hi Shaun,
                                                                        It’s Great! Surely there is a bug on firmware upload of Arduino WiFi Rev2.
                                                                        I’m going to write to Arduino.
                                                                        Thank again Renzo

                                                                  Viewing 18 reply threads
                                                                  • You must be logged in to reply to this topic.
                                                                  Exit mobile version