Upload Sketch Problem

If I try to upload this sketch (send email form arduino) the IDE crash and any other attempt doesn’t work. If I try to upload any other Sketch works fine, I have this problem only with this one. I use an Arduino MEGA board.

Thanks

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x58, 0x25 };
byte ip[] = { xx,xx,xx,xx };
byte gateway[] = { xx,xx,xx,xx };
byte subnet[] = { xx,xx,xx,xx };
byte server[] = { xx,xx,xx,xx }; // SMTP server

int time = 5000;
int wait = 1000;

Client client(server, 25);

void setup()
{
  delay(time); /* allow the router to identify the Arduino before the Arduino connects to the internet */
  Serial.begin(9600);
  Serial.println("Program started, waiting for router..."); 
  delay(time); /* allow the router to identify the Arduino before the Arduino connects to the internet */
  Serial.println("Starting network module...");
  Ethernet.begin(mac, ip, gateway,subnet);
  delay(wait);
 
 Serial.println("connecting...");
 
 if (client.connect()) {
    Serial.println("connected");
 
 client.println("HELO xxxxxxx.it"); /* say hello*/
 delay(wait); /* wait for a response */
 client.println("MAIL From: xxxxx@xxxxxx.it"); /* identify sender */
 //delay(wait); /* wait for a response */
 client.println("RCPT To: xxxxxx@xxxxxxx.it"); /* identify recipient */
 //delay(wait); /* wait for a response */
 client.println("DATA"); 
 //delay(wait); /* wait for a response */
 client.println("To: xxxxxxx@xxxxxxxx.com"); /* identify recipient */
 client.println("Subject: xxxxxxxxxxxx"); /* insert subject */
 client.println("xxxxxxxxxxx"); /* insert body */
 client.println("QUIT"); /* terminate connection */
 delay(wait); /* wait for a response */
   
 client.println();
  
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }
 
 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   for(;;)
     ;
 }
}

Moderator edit: code tags added.