How to notify email without press reset button

Serial.print("distance ( ): ");
Serial.println(distance);
Serial.print("Level (Ml): ");
Serial.println(levelMl);

display.clearDisplay();
display.setCursor(0, 25);
//Display level in Liter
display.print(distance);
display.print("");

// Display distance in inches
/* display.print(distanceInch);
display.print(" in");*/
display.display();
delay(500);

Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();

/** Enable the debug via Serial port

  • none debug or 0
  • basic debug or 1
    */
    smtp.debug(1);

/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);

/* Declare the session config data */
ESP_Mail_Session session;

/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = "";

/* Declare the message class */
SMTP_Message message;

/* Set the message headers */
message.sender.name = "GARBAGE MONITORING SYSTEM POLITEKNIK MERSING";
message.sender.email = AUTHOR_EMAIL;
message.subject = "STATUS GARBAGE";
message.addRecipient("Afrina", RECIPIENT_EMAIL);

//Send HTML message/
String htmlMsg = "<div style="color:#2f4468;">

GARBAGE IS FULL!

- Please pickup the rubbish

";
message.html.content = htmlMsg.c_str();
message.html.content = htmlMsg.c_str();
message.text.charSet = "us-ascii";
message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

/* Set the custom message header */
//message.addHeader("Message-ID: abcde.fghij@gmail.com");

/* Connect to server with the session config */
if (!smtp.connect(&session))
return;

/* Start sending Email and close the session */
if (!MailClient.sendMail(&smtp, &message))
Serial.println("Error sending Email, " + smtp.errorReason());

}

}
void loop() {

Serial.println();
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculate the level
distance = duration * SOUND_SPEED/2;

// Convert to inches
//levelMl = distance * LITER_TO_ML;

Serial.println (distance);

if (distance >= 2 && distance <= 9) {
Serial.println ("STATUS = FULL \n ") ;
Serial.println ("100%");
Serial.println (distance);
digitalWrite (led1, HIGH);
digitalWrite (led2, LOW);
digitalWrite (led3, LOW);
digitalWrite(oledPin,HIGH);
display.setCursor(0, 25);
display.print ("STATUS = FULL \n ") ;
display.print ("100%");
delay(900);
}

else if (distance >= 10 && distance <= 20 ) {
Serial.println ("STATUS = HALF \n ") ;
Serial.println ("50%");
digitalWrite(oledPin,LOW);
digitalWrite (led1, LOW);
digitalWrite (led2, HIGH);
digitalWrite (led3, LOW);
display.setCursor(0, 25);
display.print ("STATUS = HALF \n ") ;
display.print ("50%");
delay(900);
}

else {
Serial.println ("STATUS = LOW \n ") ;
digitalWrite(oledPin,HIGH);
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
digitalWrite (led3, HIGH);
display.setCursor(0, 25);
display.print("STATUS = LOW \n ");
delay(900);
}

display.display();
display.clearDisplay();

}
/* Callback function to get the Email sending status /
void smtpCallback(SMTP_Status status){
/
Print the current status */
Serial.println(status.info());

Serial.println (distance);

/* Print the sending result */
if (distance >= 2 && distance <= 9) {
Serial.println("----------------");
Serial.println ("STATUS = FULL \n ") ;
Serial.println ("100%");
Serial.println (distance);
digitalWrite (led1, HIGH);
digitalWrite (led2, LOW);
digitalWrite (led3, LOW);
digitalWrite(oledPin,HIGH);
display.setCursor(0, 25);
display.print ("STATUS = FULL \n ") ;
display.print ("100%");
delay(900);
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
struct tm dt;
}

else if (distance >= 10 && distance <= 20 ) {
Serial.println ("STATUS = HALF \n ") ;
Serial.println ("50%");
digitalWrite(oledPin,LOW);
digitalWrite (led1, LOW);
digitalWrite (led2, HIGH);
digitalWrite (led3, LOW);
display.setCursor(0, 25);
display.print ("STATUS = HALF \n ") ;
display.print ("50%");
delay(900);
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
struct tm dt;
}

else {
Serial.println ("STATUS = LOW \n ") ;
digitalWrite(oledPin,HIGH);
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
digitalWrite (led3, HIGH);
display.setCursor(0, 25);
display.print("STATUS = LOW \n ");
delay(900);ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
struct tm dt;

for (size_t i = 0; i < smtp.sendingResult.size(); i++){
  /* Get the result item */
  SMTP_Result result = smtp.sendingResult.getItem(i);
  time_t ts = (time_t)result.timestamp;
  localtime_r(&ts, &dt);

  ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
  ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
  ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
  ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str());
  ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");

}
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Please post your full sketch, using code tags when you do

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.