View Single Post
  #1  
Old 6th April 2011, 11:56
Mark_NL Mark_NL is offline
Senior Member
 
Join Date: Sep 2008
Location: The Netherlands
Posts: 912
Thanks: 12
Thanked 100 Times in 96 Posts
Default Triggering a script when mail is received on some address in ISPConfig3

Well, i started this post to ask for your assistance .. but while i was typing, and double checking everything i resolved the problem.

Instead of closing this window and go on with my day i thought it might be useful to post my solution so others can benefit from it in case they run into the same problem (i couldn't find anything on the forum btw)

Anyway, i wanted to trigger a script when i received an email on a specified address (bounce@domain.tld).

so ..

vi /etc/aliases
Code:
bounce: "|/data/scripts/processbounce.sh"
Code:
newaliases
Code:
/etc/init.d/postfix reload
The problem i ran into here was that, postfix didn't knew "bounce@domain.tld", so i got this error:
Quote:
Apr 6 09:42:55 domain-mail postfix/smtpd[23960]: NOQUEUE: reject: RCPT from mail.mydomain.tld[1.2.3.4]: 550 5.1.1 <bounce@domain.tld>: Recipient address rejected: User unknown in virtual mailbox table; from=<mark@mydomain.tld> to=<bounce@domain.tld> proto=ESMTP helo=<mail.mydomain.tld>
Oke, well let's make a virtual user (bounce@ should not be a real mailbox)

So in ISPConfig3 i added a "Mail forward"
E-Mail: bounce @ domain.tld
Destination Email: bounce

By not adding a domain after "bounce" this will become a local user on this system, hence it will be picked up by "aliasses" (where we said: run script X when mail for bounce).

New test!

Quote:
Apr 6 09:16:05 domain-mail amavis[21988]: (21988-08) Passed CLEAN, [1.2.3.4] [5.6.7.8] <mark@mydomain.tld> -> <bounce@domain.tld>, Message-ID: <4D9C1310.1050007@mydomain.tld>, mail_id: ZbitfjKRIENQ, Hits: -0.001, size: 1359, queued_as: 48A52819C7, 2170 ms

Apr 6 09:16:05 domain-mail postfix/smtp[23197]: 1C8EB819C6: to=<bounce@domain.tld>, relay=127.0.0.1[127.0.0.1]:10024, delay=2.3, delays=0.14/0.01/0/2.2, dsn=2.0.0, status=sent (250 2.0.0 Ok, id=21988-08, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 48A52819C7)

Apr 6 09:16:05 domain-mail postfix/smtp[23158]: 48A52819C7: to=<bounce@mail.domain.tld>, orig_to=<bounce@domain.tld>, relay=none, delay=0.07, delays=0.07/0/0/0, dsn=5.4.6, status=bounced (mail for mail.domain.tld loops back to myself)
mail.domain.tld is indeed the same machine, so we need to tell postfix that he is mail.domain.tld as destination so add "mail.domain.tld" to "mydestination" in /etc/postfix/main.cf

Quote:
mydestination = domain-mail.domain.tld, localhost, localhost.localdomain mail.domain.tld
new test!

Quote:
Apr 6 09:57:35 domain-mail postfix/local[24529]: 60BBD819D0: to=<bounce@mail.domain.tld>, orig_to=<bounce@domain.tld>, relay=local, delay=568, delays=568/0/0/0.04, dsn=2.0.0, status=sent (delivered to command: /data/scripts/processbounce.sh)
et voila!

Regards,
Mark

P.S. Adding a virtual alias map didn't work. And now we keep using ispconfig's interface, which imho is more neat.
Reply With Quote
Sponsored Links