In a large saucepan over medium heat, heat the olive oil, add the onion, and fry, stirring occasionally, until soft. Then add the minced garlic and cook for about 1 minute. Put the mashed tomatoes, jam, oregano, basil, salt, and pepper in a saucepan. Bring the mixture to a boil. Reduce heat, simmer uncovered for about 20 minutes, stirring occasionally.
Meanwhile, spread the cheese slices over 4 slices of bread and cover with the remaining 4 slices. In a small bowl, combine eggs, milk, salt, and black pepper. Dip the cheese sandwiches into this mixture.
In a large skillet over medium-high heat, heat 1 tablespoon butter. Put sandwiches with cheese in a preheated pan, fry over low heat until golden brown, about 4-5 minutes on each side (the cheese should melt). Repeat the process with the rest of the butter and sandwiches.