0

This question more is for learning purpose.

I'm exploring ways to develop a small email server (in + out).

I have a domain that points to my server as well as mx records and all that stuff...

I also have the open ports 25, 26, 110, 993, 995, 143, 465....

I'd like to activate a shell script on incoming email.

I have apache + php running without problem. I type my domain on a browser => I see my pages from anywhere. (that part is done).

I don't exactly know where to start...

There is tons of stuff when I search

I tried dovecot, mailhog, exim but I'm having difficulty to get them up and running.

My question is more : "is there a way to listen to port x for emails => when a email arrives => execute a script (in the rawest form possible)" ?

Jintor
  • 139
  • 6
  • Sure. You can program anything, including an SMTP server, to do as little or as much as you desire. – Paul Dec 21 '21 at 23:10
  • @Paul would you know a documentation or starting point ? python, php, .sh, do you have a recommendation? the main stuff I miss it the how to "catch" or "listen" for an incoming file .... Once I get the incoming file it will be easier... – Jintor Dec 22 '21 at 01:37

1 Answers1

3

You can start by reading RFC 5321 and RFC 5322 that define SMTP protocol and email message format. Once you finished with these two, you can continue reading all other email-related RFCs.

When you familiarize yourself with the depth of the rabbit hole you are going to jump into, you can try Python simple SMTPD (deprecated) or aiosmtpd. You'll also need email.parser to parse incoming emails and extracting files.

And the answers to the question "Is it possible to trigger a shell script on incoming emails, can it be done without services like dovecot, postix, etc?" are here and here (actually, I have misread the question as written "with postfix" instead of "without" but I'll leave the links anyway)

AlexD
  • 8,179
  • 2
  • 28
  • 38