In a large heavy pot, preheat the vegetable oil to between 350 degrees F (175 degrees C) and 375 degrees F (190 degrees C).
Shuck, wash and dry the corn. Using a sharp knife, shave the ears of corn into a medium sized bowl. Using a cheese grater, scrape any remaining corn and juice into the bowl with the kernels. Discard the scraped cobs.
In a mixing bowl, whisk together the eggs and milk. Combine the corn, ham, cayenne pepper, red onion, salt, flour and baking powder with the egg and milk mixture. Whisk until a firm batter has formed.
Slowly drop rounded tablespoonfuls of the batter into the hot oil one at a time. The drops should form a loose layer on the top of the oil. Fry until the drops of batter are dark golden brown. Remove the beignets from the oil and place them on a towel. Check that they are cooked all the way through. If the centers are doughy, lower the heat of the oil and fry the beignets again for 2 or 3 minutes. Repeat this step until all the batter has been used.