Home › Forums › The libraries hosted on the site › EMailSender send email with attachments › Arduino MKR WiFi 1010 can’t log SMTP Gmail with sketch
Tagged: ARDUINO MKR WIFI 1010, GMail, SMTP
- This topic has 9 replies, 1 voice, and was last updated 4 years, 4 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
18 December 2020 at 07:59 #8952
Maulepilot
I haven’t been able to log into Gmail using your EMailSenderESP32GMailTest sketch with my Arduino MKR WiFi 1010 and the Arduino.h, WiFiNINA.h and EMailSender.h libraries. I get the following messages on the serial monitor:
Connection: ESTABLISHED
Got IP address: 192.168.1.42
Sending status:
0
1
SMTP Response TIMEOUT!I’ve tried using the two parameter emailSend constructor with my gmail userid and password as well as the longer constructor with my gmail userid, password, mail from userid, smtp.gmail.com as the outgoing server and port 587, as well as port 465.
I went through parts 1 and 2 of your tutorial but it hasn’t helped. I’m wondering if your EMailSender.h library isn’t compatible with the MKR WiFi 1010.
I logged out of Google completely and logged back in with a browser to make sure my Gmail account was working and it’s fine. There are no sent messages from the Arduino.
Any advice? Thanks.
-
18 December 2020 at 08:02 #8954
Hi manuelpilot,
- please check is lessecureapp is activated,
- if you tried to spoof the sender address using google smtp (for instance, using FromAddress as something other than the name of my gmail account)
- check if you have some network limitation from firewall or VPN redirect.
Give me a feedback Bye Renzo
-
18 December 2020 at 08:02 #8955
Maulepilot
Yes, lesssecureapp is activated. Yes, I used my own gmail account as the FromAddress. I don’t think there’s any kind of network limitation or firewall problem. I’ve been sending POST messages to a PHP script that I wrote on a GoDaddy shared HTTPS server without any problems.
-
18 December 2020 at 08:03 #8956
It’s very strange, I try to send an email now from an esp32 DEV KIT v1 and work correctly.
Please post your code, and in the file EMailSenderKey.h uncomment this line
//#define EMAIL_SENDER_DEBUG
and send the result (cover the login and passwd).
Thanks Renzo -
18 December 2020 at 08:06 #8957
Maulepilot
Here’s your slightly modified sketch. I have to use #include <WiFiNINA.h> to compile without errors. That might be the problem but I can’t tell for sure. All the private information in caps is defined in the #include “arduino_secrets_gmail.h” file.
/* EMailSender library for Arduino, esp8266 and esp32 Simple esp32 Gmail send example http://mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/ */ #include "Arduino.h" #include #include #include "arduino_secrets_gmail.h" const char* ssid = SECRET_SSID; const char* password = SECRET_PASS; uint8_t connection_state = 0; uint16_t reconnect_interval = 10000; EMailSender emailSend(SECRET_GMAIL_USERNAME, SECRET_GMAIL_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 = "Soggetto"; message.message = "Ciao come stai io bene. www.mischianti.org"; EMailSender::Response resp = emailSend.send(SECRET_GMAIL_RECIPIENT, message); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); } void loop() { }
Here’s the serial monitor output with the #define EMAIL_SENDER_DEBUG in EmailSender.h library file uncommented. I didn’t include the SSID network name at the top for privacy’s sake. I’m wondering if the fact that it’s an insecure client is what is causing the problem. I tried temporarily changing #include <WiFi.h> to #include <WiFiNINA.h> in your EmailSender.h file but it didn’t help. I’ve had to change WiFi.h to WiFiNINA.h in all of the sketch examples in order to compile them without errors on the MKR WiFi 1010.
Connection: ESTABLISHED Got IP address: 192.168.1.42 ONLY ONE RECIPIENTInsecure client:0 Sending status: 0 1 SMTP Response TIMEOUT!
-
18 December 2020 at 08:06 #8958
Hi Mauelepilot,
to send email with MKR WiFi 1010 and WiFININA you must do some additional work.
I find this
https://gitlab.com/gratefulfrog/arduino-wifinina-gmail-smtp
seems you must enable 2 factor security and generate secret.
Give me a feedback if this can solve the problem
Bye Renzo -
18 December 2020 at 08:10 #8959
Maulepilot
Thanks, Renzo. I was successful using the arduino-wifinina-gmail-smtp library and modified WiFiSSLClient_gmail_smtp sketch by Grateful Frog above. The process is complex. In Google Account Manager I created a separate gmail account, set up 2 factor authentication and created an app password. The app password must be used when logging into the gmail account. In the modified sketch I removed all private data from the sketch and put it in the arduino_secrets.h file. Here the sketch and the output from the serial monitor.
Attachments:
You must be logged in to view attached files.-
20 January 2021 at 21:44 #9479
Hi manuelpilot,
now the official library support Arduino SAMD board (WiFiNINA), you can find additional information here.
Send email with attachments: Arduino SAMD boards (WiFiNINA) – 3
Bye Renzo
-
-
18 December 2020 at 08:11 #8960
Perfect!
In the future I try to integrate the process in my library, but now I’m happy that you had found the solution.
Bye RenzoI think I only add/change this part
WiFiSSLClient client; if (client.connectSSL(server, port)==1){
and all work.
-
4 January 2021 at 21:54 #9222
Hi Maulepilot,
I extend support from my library, you can find the update library that fully support Arduino MRK WiFi 1010 at this branch, I’m going to release soon.
GitHub WiFiNINA SAMD support branch
If you can give me a feedback.
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.