Lay out the four slices of bread. Spread mayonnaise on one side of two of the slices.
On the mayo-spread slices, layer the ham and then the Gruyère cheese. Top with the remaining two slices of bread to form two sandwiches. Press each one down firmly.
In a shallow dish wide enough for a sandwich, whisk together the egg, milk, and salt until well combined.
Melt the butter in a large nonstick skillet or griddle over medium heat until it sizzles.
Briefly dip one sandwich into the egg mixture, coating both sides for just a few seconds. Do not let it soak.
Immediately transfer the egg-coated sandwich to the hot skillet.
Cook for 3 to 4 minutes per side, pressing down occasionally with a spatula, until the outside is golden brown and the cheese is fully melted.
To ensure the egg custard is cooked through, the sandwich's internal temperature should reach at least 160°F (71°C).
Remove from the skillet and repeat with the second sandwich. Serve hot.