Closed maulepilot closed 3 years ago
Hi manuelpilot,
Give me a feedback Bye Renzo
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.
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
/*
*/
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<br>io bene.<br>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() {
Connection: ESTABLISHED Got IP address: 192.168.1.42 ONLY ONE RECIPIENTInsecure client:0 Sending status: 0 1 SMTP Response TIMEOUT!
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
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. Attached are the sketch and the output from the serial monitor. gmailoutput-1.txt
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 Renzo
I think I only add/change this part
WiFiSSLClient client;
if (client.connectSSL(server, port)==1){
and all work.
Hi Manuelpilot, if you can add the sketch also for people that can need It. Thanks Renzo
Attached are the Arduino sketch and the serial monitor output (minus personal data). wifisslclientgmail_sketch.txt wifisslclientgmail_output.txt
Thanks 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.