I'm trying to figure out how email proxies generally work. I want to present the way I see the architecture, would be glad if anyone could explain which of my assumptions is flawed and what am I missing.
Assume I've purchased an email domain, let's say example.com
, now I want to proxy all emails arriving to my domain, do some computation on them and then either drop the email or forward it to the destination based on the computation result.
- I will change
MX
record for example.com
to arrive to my email proxy server that will be available via some public ip or domain
- Now all emails arrive to my proxy server, i can then write some custom code, analyze the email and either drop it or decide to forward
- Now comes the unclear part for me, how do I forward the email? Do i just resend it with the same sender and recipients? Then obviously I won't be able to pass authentication on the destination server as I'm not allowed to send emails from every possible domain.
My understanding is that I should somehow whitelist my proxy by IP or domain on the email destination? To basically allow emails arriving from my proxy to bypass authentication?
So that's what I tried to do:
When sending email I need to specify SMTP server and port, if I'm forwarding email, should this be a sender SMTP server or recipient SMTP server? If yes how can I skip sender authentication on the destination?
As a small POC I tried to just send unauthenticated email from my personal gmail to my personal outlook, so I've sent an email via smtp.office365.com:587
and I've whitelisted IP of the machine I've sent an email from on Outlook side but it didn't work. I was failing with:
could not send email 1: 530 5.7.57 Client not authenticated to send mail. [VI1P194CA0052.EURP194.PROD.OUTLOOK.COM]"
Any help is appreciated.
Also if anyone familiar with some existing solutions that allow injecting custom code for handling will be happy to know.