- This topic has 32 replies, 3 voices, and was last updated 3 years, 5 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
24 November 2021 at 19:21 #16507
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() { }
-
24 November 2021 at 23:57 #16516
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 -
25 November 2021 at 00:36 #16518
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?
-
25 November 2021 at 08:07 #16519
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 -
26 November 2021 at 19:23 #16565
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?
-
26 November 2021 at 20:21 #16566
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
-
26 November 2021 at 23:45 #16567
#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() { }
-
27 November 2021 at 00:02 #16568
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?
-
27 November 2021 at 08:30 #16569
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 -
27 November 2021 at 16:26 #16572
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
-
-
27 November 2021 at 19:53 #16573
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.
-
27 November 2021 at 21:14 #16575
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
-
27 November 2021 at 22:00 #16576
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?
-
27 November 2021 at 22:39 #16577
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 -
27 November 2021 at 23:03 #16578
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?
-
17 December 2021 at 15:18 #17163
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?
-
-
28 November 2021 at 08:10 #16581
Hi r0vert,
sorry but the problem can be your network or the certificate, I don’t know how to help you better.
Bye Renzo -
28 November 2021 at 18:29 #16607
Hi Renzo,
It’s all good, I’ll keep trying to figure it out. Thank you so much for your time and help!
-
10 December 2021 at 16:17 #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 :-(.
-
10 December 2021 at 22:07 #16971
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-
17 December 2021 at 16:22 #17166
Could it be to do with the version number of the WiFiNINA ? Do you know what version you last had working?
-
17 December 2021 at 17:30 #17170
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 -
17 December 2021 at 19:53 #17171
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
-
20 December 2021 at 10:32 #17192
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
-
-
11 December 2021 at 08:48 #16972
Hi all,
can you send me the configuration of EMailSenderKey.hYou 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
-
17 December 2021 at 15:21 #17164
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
-
-
20 December 2021 at 12:17 #17196
OK – I think I found a fix – for at least me anyway, I noticed something on this site:
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?!?!
-
20 December 2021 at 12:20 #17200
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
-
20 December 2021 at 12:54 #17203
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?
-
20 December 2021 at 14:30 #17205
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.