Well, there are two ways.
1. Simply just a reed switch on the flap, since often the notification that the flap has been opened is enough. In 99% of cases, there is something inside. As Leo describes it with 2 switches, it is even more convenient.
2. However, I have an optical barrier solution, because then a notification only occurs in 100% of cases; as soon as the optical barrier is free again, the notification disappears.