Letters are received via smtp protocol, in your case, I also assume that on port 25 there is a service that will listen to a request for mail from external domains.
There are various ways to bounce a message.
-> bounce at smtp level, as in the case when u receives the list of recipients, check f or the identifier, and if it does not exist, give the answer 4xx. Bouncemai l is then automatically generated by the sender domain.
-> if you received mail from the say gmail.com domain, then you will need to establish a new connection with gmail with your extension, the same as sending new mail from your server to gmail.com.
source share