0

I'm running Dovecot mail server and postfix on CentOS which serves many virtual hosts and now I have searching around hour's and reading lot of some more useful some complete junk material about how to force all incoming mails to one mail user under each domain for example:

http-post@* //(any existing allowed host)

to be delivered as HTTP POST to fixed URL and not into to mail box. but I can't find really any info what would be The Right way to do it. I already tried approach from postfix side of same mail domains but without success. Right now I'm reading about Dovecot and Sieve but it seems like lot of upcoming reading and I'm not sure am I going to right direction. For development of other-end and testing purposes I created and used a small sh script to sniff mail and send HTTP POSTs but now when everything seems ready for production I'm stuck.

How can I achieve that the right Way?

mkungla
  • 121
  • 7

2 Answers2

1

So i'm still in search of the right Way, but for those who come across similar question here is my working dirty method :)

1. Add alias to /etc/aliases

#for my coal for all http-post user under any domain
http-post: |/etc/postfix/mailworker.sh
# or you can make it for specific email
http-post@example.com: |/etc/postfix/mailworker.sh
# or forward it to mail and script
http-post@example.com: your@email.com,|/etc/postfix/mailworker.sh

2. Apply

..]# newaliases
..]# service postfix restart

3. Create file and tmp folder

..]# mkdir /tmp/mailworker
..]# vi /etc/postfix/mailworker.sh

File contents

#!/bin/bash
cd /tmp/mailworker
read mailfrom
read mailreturnpath
# Could read more headers individually 

cat > data-$$
messageFull=`cat data-$$`
messageSafe=$(echo -ne $messageFull | base64);

# Here you do anything you want with email
# As i mentioned for testing I do something very bad here ;) so don't ever do that on any production environment
mysql -h localhost -u myusername -pMyPass1 mydatabase -e "INSERT INTO mytable (id,insdate,mailfrom,mailreturnpath,message) values(NULL,NULL,'$mailfrom','$mailreturnpath','$messageSafe');"
rm -f /tmp/mailworker/data-$$

And that's it!

but what I'm looking for is how to do it clean and secure way hence i have different bizarre ideas what to do with emails :) like cleaning up message and forwarding it to web socket which is used by my internal chat and so on...

mkungla
  • 121
  • 7
  • While you'll need to add a one lne script to convert it into a n HTTP POST, you'll save yourself a lot of pain by using procmail as your MDA. – symcbean Apr 02 '13 at 21:42
  • @symcbean maybe your correct but years my set up is CentOS, Postfix, Dovecot and for me it means rebuilding lot of machines :) – mkungla Apr 02 '13 at 21:50
0

So, are you trying to filter all mail under a domain to a single user, or just all junk mail?

The first you can do with catchall aliases in your MTA. Postfix will allow you to send mail by user/domain/transport to a script, it's probably a good place to start..

The second might be better done with the program that scores your junk mail, amavisd-new has the final_spam_destiny, spamasssasin can be hooked into fetchmail or .procrc. Sieve is another option, although it's rather late in the process.

NickW
  • 10,263
  • 1
  • 20
  • 27
  • It's not really what I want. I all ready have spam handled and mail server it self is fully operational and fine what I try to achive is to force all incoming mail to any domains admin mail to be sent as HTTP POST to fixed url – mkungla Apr 02 '13 at 11:33
  • 1
    That's not super clear from your question. If you need to send a particular users email to a script, have a look through the filter-readme for postfix, you can then write a script as the destination. – NickW Apr 02 '13 at 11:50