Tagged: Help
- This topic has 6 replies, 2 voices, and was last updated 2 years, 10 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
4 July 2022 at 07:50 #21559
Hi Renzo,
I get a funny issue.
When the send code is within a IF syntax, I got the error “Could not connect to mail server” with Email2
When the code is outside the IF syntax, it works. (Email1)
Can anyone help me to fix this?
Connection is made with Arduino cloud code, but I think that’s the same than ESP8266WiFi.h
See code below.
Many thanks!!
Andrea
#include "arduino_secrets.h" #include "thingProperties.h" #include "Arduino.h" #include <EMailSender.h> #include <ESP8266WiFi.h> EMailSender emailSend("12345@gmail.com", "54321"); void setup() { // Initialize serial and wait for port to open: Serial.begin(9600); // This delay gives the chance to wait for a Serial Monitor without blocking if none is found delay(1500); pinMode(14, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(A0, INPUT); // Defined in thingProperties.h initProperties(); // Connect to Arduino IoT Cloud ArduinoCloud.begin(ArduinoIoTPreferredConnection); /* The following function allows you to obtain more information related to the state of network and IoT Cloud connection and errors the higher number the more granular information you’ll get. The default is 0 (only errors). Maximum is 4 */ setDebugMessageLevel(2); ArduinoCloud.printDebugInfo(); } void loop() { ArduinoCloud.update(); digitalWrite(14, bitRead(1, 0)); digitalWrite(12, bitRead(1, 1)); digitalWrite(13, bitRead(1, 2)); sensore = analogRead(A0); Email1(); if (sensore < 300) { bottone = true; Email2(); } else { bottone = false; } } void Email1() { EMailSender::EMailMessage message; message.subject = "Email"; message.message = "Ciao come stai<br> io bene .<br>www.mischianti.org"; EMailSender::Response resp = emailSend.send("alpes.andrea@gmail.com", message); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); delay(1000); } void Email2() { EMailSender::EMailMessage message; message.subject = "Email IF"; message.message = "Ciao come stai<br> io bene .<br>www.mischianti.org"; EMailSender::Response resp = emailSend.send("alpes.andrea@gmail.com", message); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); delay(1000); }
-
4 July 2022 at 08:39 #21565
Hi ozzy,
probably GMail blocked the attempt to send an email too close to the previous email (prevent spam).
Try to add adelay(10000);
or more before the secondEmail2();
Bye Renzo
-
4 July 2022 at 10:21 #21566
Hi Renzo,
I added a delay(10000) to the code but I got the same issue.
I even removed Email1 but I still get the same error “Could not connect to mail server”.
If I move Email1 out of the IF syntax, then it works which sounds really crazy to me.
Do you have any clue?
Thanks!!
Andrea
-
4 July 2022 at 15:44 #21568
Can you send me all the serial output (with debugging enabled)?
Bye Renzo -
4 July 2022 at 19:04 #21571
Hi Renzo,
please see the serial output below.
Once WIFI connection has been established, the Email1 is sent every 500 millis.
Once the sensore Luminosità < 300, the the IF function is triggered but Email2 got error “Could not connect to mail server”.
I’d suggest you to try to write a sketch using connection from Arduino cloud.
Should you need more information, please let me know.
Donation for your assistance will follow shortly.
Many thanks,
Andrea
connected with Ozzy, channel 1
dhcp client start…
ip:192.168.1.36,mask:255.255.255.0,gw:192.168.1.1
Sending status:
1
0
Message sent!
Connected to “Ozzy”
Luminosita’ 408
Sending status:
1
0
Message sent!
Luminosita’ 406
Sending status:
1
0
Message sent!
Luminosita’ 122
Sending status:
0
2
Could not connect to mail server
Sending status:
0
2
Could not connect to mail server
Luminosita’ 114
Sending status:
0
2
Could not connect to mail server
Sending status:
0
2 -
4 July 2022 at 21:47 #21572
Hi Renzo,
good news.
When condition is “if (sensore > 300)” it works ! 🙂
better than nothing. 😉
I think I’ll fix the code with a trick.
Thank you!
Andrea
-
4 July 2022 at 22:45 #21578
Hehehehhe… but I think the problem is the sending frequencies of the email, probably GMail block the multiple sending if the second email is too close to the previous.
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.