Cook spaghetti in salted water for about 8 minutes, then drain. In the meantime cut ham into fine strips. Peel and finely chop the onion. Wash and halve the tomatoes.
Wash the basil, pluck the leaves, chop if necessary. Heat oil. Brown onion and ham in it. Briefly sauté the tomatoes and basil in the cooking fat. Fill spaghetti and ham mixture into a form.
Whisk egg and milk. Season with salt and pepper and pour over. Bake in the preheated oven (electric cooker: 225 °C/ gas: level 4) for approx. 8 minutes. Serve with freshly sliced parmesan and fresh basil.