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() {
}
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
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?
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?
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?
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
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
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.
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.
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?
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?
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?
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 :-(.
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
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.
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
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?
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.