www.linuxexpert.ro

Tutorials

  • Home
  • BGP Tutorials
    • Remove private AS
  • cPanel Tutorials
    • Install ImageMagick on cPanel
    • Install Softaculous
  • Linux Tutorials
    • Auto-reboot Linux after kernel panic
    • Building a firewall with Iptables
    • Change array RAID 1 disk order
    • Configure ntfs-3g on Linux Slackware
    • DHCP Option Codes
    • DansGuardian with Squid and ClamAV
    • Fetchmail for Gmail accounts
    • Install Zend & APC PHP Optimizers
    • Install Atheros AR242x PCI Express Adapter
    • Install awstats with DirectAdmin
    • Install DBD::mysql via CPAN shell
    • Install DjbDNS on Ubuntu
    • Installing fail2ban on Centos 5
    • Install GoDaddy SSL Certificate
    • Install i386 packages under x86_64
    • Install Linux via USB flashdrive
    • Install ModSecurity2 on Apache2.0.x
    • Install Nginx on CentOS
    • Install webalizer with ispconfig
    • Install intel A/B/G/N wireless on linux
    • Kernel Upgrade
    • Mobile phone access via bluetooth
    • Optimize MySQL
    • Optimize Qmail
    • Optimize server load
    • Optimize and Tune Apache for performance
    • Optimize and Tune Nginx for performance
    • Perfect Mailserver on Debian
    • Pidgin "Now Playing" Status Message
    • PHP hardening
    • PHP hardening with Suhosin
    • PHP5 Support allong with PHP4
    • Previewing your site before making DNS changes
    • Proxy Auto Configuration
    • PXE boot install rescue
    • Setup awstats on CentOS
    • Setup EC2 Amazon L2TP IPSec VPN
    • Setup email piping with Qmail
    • Setup Exim with DKIM
    • Setup Exim smart relay with cPanel
    • Setup OpenVPN
    • Setup postfix on nonstandard port
    • Setup SS5 Socks Proxy
    • Setup vsftp with no shell access
    • Sendmail smart relay with gmail auth
    • Squid proxy NCSA authentication
    • Tcpdump filters
    • Upgrade PHP to 5.3 in Plesk 10
    • Useful regular expressions
    • X with [SiS] 771/671 VGA controller
  • Joomla Tutorials
    • Hardening Joomla
    • Module Positions
    • Remove Joomla description meta tag
  • Looking Glasses
  • Optimize Firefox
  • Security
    • Crack WiFi WEP passwords
    • Defend against UDP isc.org DNS query DDOS
    • Detect DDoS attack
    • Remove malware from web sites
    • Sniff SSL passwords with ettercap
    • Snort2BGP
    • Track Hackers
    • What Is My IP
  • Troubleshooting
    • Grub error no such disk
    • named dumping master file: tmp-XXXXXXXXXX: open: permission denied
    • Nginx 413 Request Entity Too Large
    • SSH conection closed by remote host
    • Troubleshooting sis190.c
  • Unix Tutorials
    • FreeBSD reset root password
    • Installing snort on OpenBSD
    • Unix Toolbox
  • Virtualization Tutorials
    • Convert VirtualBox image to VMWare
    • VMware SNMP Enable
  • VoIP Tutorials
    • Install Elastix
    • Qos for Asterisk

Who's Online

We have 12 guests and no members online

Most Read

  • Setup SS5 Socks Proxy
  • Install webalizer with ispconfig
  • Sniff SSL passwords with ettercap
  • __404__
  • Optimize and Tune Apache for performance

Products and Services

  • Home
  • Linux Products and Services
  • Buy VPN Account
  • Privacy Policy for Linuxexpert
  • Remove malware

Setup email piping with Qmail

  • Print
  • Email
Details
Parent Category: Tutorials
Published: 14 April 2009
Hits: 7411

In this tutorial I'll show you how you can do email piping with qmail.


Email piping means in fact redirecting email that are coming to an email address to a php/cgi script. 

You can done this using .forward, .qmail-default, .procmailrc maildroprc, etc. 

In order to do this you must relay on two things

1. POP3 account should NOT be there for that email address from which you piping email to autoresponder script. Because POP3 catches the email before it will redirected to autoresponder script.

2. You need to set up other POP3 accounts for your regular correspondence like This email address is being protected from spambots. You need JavaScript enabled to view it. or This email address is being protected from spambots. You need JavaScript enabled to view it. etc., so these regular email won't be redirected to autoresponder.

Ask your host this question: 'Can I redirect(pipe) email from my catch-all email account to a php script?'

AutoResponders
An auto-responder is similar to a mailing list, but it simply responds with a pre-defined message to the person who sent the mail. The most common program for this purpose is vacation. However, this program may not be sufficient for most purposes. I will begin with an annoying trait of system e-mail configuration. Many people in their attempts to block unwanted mail have implemented routines that analyze the envelope sender of a message. For instance, if the sender's domain has no entry, then it will not accept the message. Another thing they will try to do is block all mail from <>. This is a foolhardy thing to do. Not only will user's not be able to get bounce messages, it makes it more difficult to send auto-responses. The next step would be to create a bit-bucket address for the envelope sender and do some trickery with the "From:" header. In my situation, I would like "From:" to point to the autoresponder that sent the response. If you rely on this situation, you can potentially create a mail loop because some (albeit ignorant) mail systems will respond to the "From:" header and not the envelope sender. The only sure-fire solution is to set the "From:" header and the envelope sender the same as the autoresponder, and then check for mail received from the same address over n times over some period of time. You can check for certain addresses, such as <>, #@[], postmaster@, mailer-daemon@, etc. to crack down on some of the more worthless mail you don't want to autorespond to.
Double Bounces
A double bounce is created when a bounce bounces on its way back. This normally indicates a configuration error (you should always have your envelope sender set up as a valid address, or <> or #@[]). If a bounce bounces and the envelope sender is <> or #@[] then it is ignored. But if it is an address, then the bounce will be sent to that address. If the address fails, then the double bounce situation occurs. Qmail will then send a QSBMF message to the doublebounce address (by default this is postmaster). Note that SMTP prevents envelope senders to be #@[], and thus it is only used in the internals of a qmail system.
Bounce Handling in Qmail Configuration
Qmail has several configuration items that can help you control bounce messages. Here are several for the control directory.
qmail-send
bouncefrom
The user name of a bounce message. Default is MAILER-DAEMON
bouncehost
The host of a bounce message. By default it is me. If that is not supplied, then it is bouncehost.
doublebouncehost
The host of a bounce message. By default it is me. If that is not supplied, then it is doublebouncehost.
doublebounceto
The user to receive double bounce messages. By default it is postmaster.
queuelifetime
The lifetime in seconds a message can stay in the queue. By default it is 604800 (one week). If a message temporarily fails over and over again, after it has been in the queue for this period of time and receives another temporary failure, then it will permanently fail and a bounce will be generated.
qmail-smtpd
badmailfrom
Unacceptable envelope sender addresses. qmail-smtpd will reject every recipient address for a message if the envelope sender address is listed in badmailfrom. A line in badmailfrom may be of the form @host, meaning every address at host.

Some further things you can do to control the bounce behavior:

To have an address automatically bounce a message, put the following into a .qmail file:

|exit 100

Read the qmail-command man page for other exit codes.

If a message is sitting in the queue, and you would like it to bounce right now, touch the appropriate info file with a time sufficiently in the past (beyond queuelifetime) and give qmail-send an ALRM signal. Note that qmail-send will try to send it one more time before it will bounce it. Is there a better way to do this?

 

Qmail

If you are a normal user, you can create an alias by saving a file called .qmail-foo in your home directory. Email sent to This email address is being protected from spambots. You need JavaScript enabled to view it. is then sent as specified in this file.

If you want to create just an alias, without being a user, eg. This email address is being protected from spambots. You need JavaScript enabled to view it., you create a .qmail file in the /var/qmail/alias directory. .qmail-myscript should do it.

Add the following to your .qmail file and save it.
|/path/to/tt/admin/cron/pipe.php

 

I have set up qmail to pass bounced emails to a php script
To Do this I created an email address called bounce

I add |/usr/bin/php -f /var/www/vhosts/domain.com/httpdocs/qbounce.php
to /var/qmail/mailnames/domain.com/.qmail

 

Hi,

I have email piping working for all the email addresses in the mster domain where Kayako sits.

e.g.
Master Domain = example.com
Email Address = This email address is being protected from spambots. You need JavaScript enabled to view it. (Works fine)
Email Address 2 = This email address is being protected from spambots. You need JavaScript enabled to view it. (Works fine)
Kayako Sits at: example.com/support

However I have setup email piping for a domain other than the master domain.

e.g. This email address is being protected from spambots. You need JavaScript enabled to view it.

This email address is piped as file name qmail-user1 with content:

|/usr/bin/php /home/example/public_html/support/cli/index.php

The wierd thing is that external email works but internal wont?!

Could it be the user behind this email address resides in another home directory?

Note:

We use Hosting and VPS Hosting, from: www.star-host.org

We like and trust them.

Good prices, high security.

fShare
Tweet