So instead of doing what everyone would do (apt-get install sendmail) I wrote a simple script in Python that works somewhat like Sendmail does, with the exception that it just forwards everything to another server. I *could* make it work without an external server, but that would require to resolve the DNS of the destination server and to find the MX registers... and I'm lazy. Plus that would require an external Python Module to do the DNS resolution, and I wanted my script to be pure-Python with no dependencies other than the Python library. Anyway if anyone, ever, needs a script to do the DNS thing, ask and I'll do it *sigh*.
So here comes the script. The script accepts the sendmail -t parameter so the "To" header from the Email is used to specify the recipients, otherwise recipients should be specified by command line.
def sendmail(from_addr, to_addrs, msg):
smtp = smtplib.SMTP(SMTP_SERVER)
smtp.sendmail(from_addr, to_addrs, msg)
msgstr = sys.stdin.read()
msg = email.message_from_string(msgstr)
if sys.argv == "-t":
to_addrs = msg["To"]
to_addrs = sys.argv[1:]
sendmail(msg["From"], to_addrs, msgstr)
Thats it! To test it:
Hello! Hows life?
I hope you liked it, happy hacking!