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);
}
Hi ozzy,
probably GMail blocked the attempt to send an email too close to the previous email (prevent spam).
Try to add a delay(10000); or more before the second Email2();
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
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
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.