Site icon Renzo Mischianti

Could not connect to mail server

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);
}

Exit mobile version