http://qs321.pair.com?node_id=329023

soffen has asked for the wisdom of the Perl Monks concerning the following question:

Long story short, I want to bounce email w/ perl - selectively. I have an email interface that I built w/ perl and HTML. Everything sent to @mydomainname.com comes into the same email box. But alot of mail is coming in at addresses I've never created or used. So, I want to bounce it.

How do you bounce an email? I can't seem to find any info anywhere on that. Any help would be appreciated.

soffen

Update 16 Apr 2014

I'm surprised I remembered the password to this account, but apparently I do.

Let me start by thanking everyone who responded - and I do mean everyone. Each of you took time out of your day to respond when doing so benefited you none. You shared with me what you knew and tried to help me find better ways to do things. And for that, I sincerely thank you.

My shame at my outburst (below) has kept me away from this forum for over a decade. Please accept my humble apologies.

soffen

Replies are listed 'Best First'.
Re: Bouncing Email w/ Perl
by tachyon (Chancellor) on Feb 14, 2004 at 20:54 UTC

    You bounce an email by sending a message back to the server that sent it. There are a number of possible messages but user unknown at this domain is what you want. See Mail::Message::Construct::Bounce for a very simple interface to bounce messages in perl. Note this link fails to work properly. Go to search.cpan.org and search for 'MAIL::Bounce' and it will bring it up OK

    However what you really want to do is not have a catch all email address. Typically this will be (for sendmail) set up in the virtusertable like this:

    [root@www root]# cat /etc/mail/virtusertable @domain.com username ...
    This directs any mail sent to domain.com to usernames mail box. All you need to do provided you have root access of course is
    cd /etc/mail/ vi virtusertable Now replace the @domain.com with address@domain.com username corporate@domain.com username bitbucket@domain.com username etc@domain.com username spam@domain.com spam Finally run make to recompile the .db file

    Now any mail to domain.com that does not match one of the listed addresses will bounce. Note multiple 'fake' addresses go to the one username mail box.

    It is easier to let the MTA bounce messages for you. Otherwise you will have to parse you mail box using the Mail::Box and friends. Note Mail::Box is the biggest pain in the ass to install as it has *lots* of dependencies, and I do mean lots. Each of these has more. Suggest use CPAN to put it on for you.

    cheers

    tachyon

Re: Bouncing Email w/ Perl
by Vautrin (Hermit) on Feb 14, 2004 at 21:45 UTC
    You should probably think carefully about bouncing e-mails. You've probably gotten a number of bounced messages you didn't write in the past due to viruses. Well you were probably as irritated deleting them as you are when you see spam, right? Bounced emails just add to the problem and clog already congested mail relays. 99.9% of spammers forge headers anyways, so you're not going to likely bounce to the right person.

    Want to support the EFF and FSF by buying cool stuff? Click here.
      Vautrin makes a very good point above. The only people likely to be writing to addresses you don't support aren't the sort of people who have their headers set up so they can properly receieve bounces.

      I do something similar to you although the details will be different.

      I have a hosting account that forwards all mail to the domain to a given address. fetchmail then retrieves the mail, and procmail filters it. Anything to a 'whitelist' address gets filtered by SpamAssassin and kept. Anything to a blacklist gets permanently deleted. Anything not on a list gets logged and held in quarantine, a report then comes to me telling me that 'A message addresses to something@domain.com' has been receieved from 'someone@somewhere.com''. I can then add that address to either list and the quarantine releases the mail. (SpamAssassin itself uses whitelists so that friends can send me stuff without it getting munged!)

      The reason I outline all this is so that I can tell you that I never bounce a message. I figure a bounce is yet another email going nowhere that noone will read.

      (The reason I do all this rather than just deleting stuff to unrecognised addresses is that I make up addresses whenever I need to. If I register here with 'perlmonks@mydomain.com' rather than 'me@mydomain.com' then I can firstly create easy-to-use filters and secondly, if I get spam sent to that address I know the owners of this site sold me out!)

        See also tarpit , which was discussed @ Spam Conference 2004. Basically, a smtp connection is throttled if the connection is trying to send spam... Cool idea.


        ----
        Zak - the office
Re: Bouncing Email w/ Perl
by iburrell (Chaplain) on Feb 14, 2004 at 23:44 UTC
    Only mail servers should send bounce email. They know the information needed to send the bounce message. For example, the From address should not receive bounce messages; the SMTP return address should get these. For most email, the from address and the return address. But think about mailing lists where the email is resent to all the members and the return address is changed to mailing list manager.

    More importantly, most of the email you are receiving for unused addresses is spam. Spammers will generate mailboxes for domains even when they haven't harvested the address. The bounce messages won't do any good because spammmers forge return and from addresses. The bounces will be going to someone innocent or invalid address. Even if they went to the spammers, the spammers will likely ignore them and not remove the bad addresses from their lists.

    The only case where bounces might be useful is if you acquired an old domain, or there used to be separate mailboxes. Then people might be legitimately using old addresses. I would suggest seeing if your ISP can do mail delivery for just the addresses that you use and bounce all the others at their server.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Bouncing Email w/ Perl
by Abigail-II (Bishop) on Feb 14, 2004 at 23:43 UTC
    Bouncing an email is best done using your MTA. How this is archieved depends on the MTA being used, and how the MTA communicates with your custom script. Often, all you need to do is exit your script with a specific exit value.

    Abigail

Re: Bouncing Email w/ Perl
by peters (Sexton) on Feb 15, 2004 at 17:28 UTC
    I agree with the others that it sounds as though you should not be bouncing these mails. If you have a good reason to bounce a mail, thouigh, I find Mail::Audit good for that among other things.
    Peter Scott... http://www.perlmedic.com
Re: Bouncing Email w/ Perl
by MidLifeXis (Monsignor) on Feb 16, 2004 at 17:49 UTC

    Reject, don't bounce. Search the SPAM-L archives for many recent threads as to why bouncing is "bad". A reject will refuse the mail before it is accepted by your system, and therefore does not make finding the correct sender your problem. If you bounce, you have now taken responsibility for sending notice to the correct sender (if you decide to).

    It is simple to forge the envelope on a mail message. If you accept then bounce, you can easily be used to send "reflect" spam via your bounce mechanism.

    I actually wrote (in perl, just to keep it slightly on topic :) a qmail delayed notification program (still available via qmail web sites, I believe), that sent notices of delayed mail in the queue to the originating party. Now days, I would not consider writing it or using it, except on a set of controlled, internal systems. The qmail "accept then bounce" model is also no longer very good in today's internet. I still use it at home, but I do not bounce, I save for spam filter fodder.