Arduino Temperature Email-Alert

I want that my arduino an email notification will be sent when the highest or lowest value was reached. He should check that every 30 minutes, and then sends a message.

The problem here is he only logs on once and a mail sent when the arduino is started and then no more.

could someone please help me?

#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define time 1000
#define emailInterval 60
#define HighThreshold 20 // Highest temperature allowed
#define LowThreshold 15 // Lowest temperature

//PIN Belegung
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12


float tempC, tempF;
char message1[35], message2[35];
char subject[] = "ARDUINO: TEMPERATURE ALERT!!\0";
unsigned long lastMessage;

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress Thermometer1 = { 0x28, 0x82, 0x92, 0x85, 0x04, 0x00, 0x00, 0x68 };

//NETZWORK
byte mac[] = { 0x64, 0xB9, 0xE8, 0xC3, 0xD7, 0xE2 };
byte ip[] = { 000000000};
byte netmask[] = { 255, 255, 255, 0 };
byte gateway[] = { 000000000 };
byte Dns[] = { 0000000000};
byte server[] = { 000000000000}; 
EthernetClient client;

void sendEmail(char subject[], char message1[], char message2[], float temp) 
{
Serial.println("connecting...");
if (client.connect(server, 25)) 
{
Serial.println("connected");
client.println("EHLO MYSERVER"); delay(time); // log in
client.println("AUTH LOGIN"); delay(time); // authorise

// enter your username here
client.println("xxxxxxxxx"); 
delay(time);
// and password here
client.println("xxxxxxxxx"); 
delay(time);

client.println("MAIL FROM:<as@gmx.de>"); delay(time);
client.println("RCPT TO:<arduino4alert@gmail.com>"); delay(time);
client.println("DATA"); delay(time);

client.println("From: <as@gmx.de>"); delay(time);
client.println("To: <arduino4alert@gmail.com>"); delay(time);
client.print("SUBJECT: ");

client.println(subject); delay(time);
client.println(); delay(time);
client.println(message1); delay(time);
client.println(message2); delay(time);
client.print("Temperature: ");
client.println(temp); delay(time);
client.println("."); delay(time);
client.println("QUIT"); delay(time);
Serial.println("Email sent.");
lastMessage=millis();
} 
else 
{
Serial.println("connection failed");
}
}
void checkEmail() 
{ 
  
// see if any data is available from client
while (client.available()) 
{
char c = client.read();
Serial.print(c);
}
if (!client.connected()) 
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}

// function to get the temperature for a device
void getTemperature(DeviceAddress deviceAddress)
{
tempC = sensors.getTempC(deviceAddress);
tempF = DallasTemperature::toFahrenheit(tempC);
}
void setup()
{
lastMessage = 0;
Ethernet.begin(mac, ip, Dns, gateway, netmask);
Serial.begin(9600);

// Start up the sensors library
sensors.begin();

// set the resolution
sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION);
delay(1000);
}
void loop()
{
sensors.requestTemperatures();
getTemperature(Thermometer1);
Serial.println(tempC);

// Is it too hot?
if (tempC >= HighThreshold && (millis()>(lastMessage+(emailInterval*1000)))) 
{
Serial.println("High Threshhold Exceeded");
char message1[] = "Temperature Sensor\0";
char message2[] = "High Threshold Exceeded\0";
sendEmail(subject, message1, message2, tempC);
} 

// too cold?
else if (tempC<= LowThreshold && (millis()>(lastMessage+(emailInterval*1000))))
Serial.println("Low Threshhold Exceeded");
char message1[] = "Temperature Sensor\0";
char message2[] = "Low Threshold Exceeded\0";

sendEmail(subject, message1, message2, tempC);
}

Moderator edit: Code tags. Again. { sigh }

You forgot to put brackets in the ‘if’ part of checking for too low a temperature. You code executes like this:

  // too cold?
  else
  if (tempC<= LowThreshold && (millis()>(lastMessage+(emailInterval*1000))))
    Serial.println("Low Threshhold Exceeded");
    
  //  These lines will get executed every time through loop().  This will likely cause problems for the email server.
  char message1[] = "Temperature Sensor\0";
  char message2[] = "Low Threshold Exceeded\0";
  sendEmail(subject, message1, message2, tempC);
}