Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Routing mail collected from a POP3 Server

by Anonymous Monk
on Apr 18, 2002 at 10:35 UTC ( #160165=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a smart mail router to collect mail from a POP3 server provided by our ISP and forward on to the intended recipients. Here why. We occasionally receive email at our office that is misaddressed i.e it is sent to fredie@ourdomain.com instead of freddie@ourdomain.com - (the user missed a 'd' out of freddie). Mail that is incorrectly addressed goes to a POP3 'catchall' account provided by our ISP. e.g ourdomian@ourdomain.com I can collect email from this catchall account with POP3Client (OK),apply some guestimations to figure out where the mail was really supposed to go and then forward it on locally or remotely via SMTP. The problem is that I cannot figure out how to reliably identify the recipients email address in the header of the original email I collect via POP3client. The mail Header To: field is obviously unreliable ('Undisclosed ricipients' etc). The topmost Received: field in the message Header contains an indented ' for <address>' that looks promising, but even this does not identify the genuine intended recipient where mails are sent to us by our ISP's list server (although in these cases the To: field is valid!). Is there information loss from the Header when POP3 email is collected that makes the task impossible? Is the unknown 'recipient for field' only going to be a problem with mail from our ISP's list server? Is there a better way to do this, rather than collecting with a POP3 Client in the first place? Any help much appreciated!

Comment on Routing mail collected from a POP3 Server
Re: Routing mail collected from a POP3 Server
by tachyon (Chancellor) on Apr 18, 2002 at 11:32 UTC

    Here is what a redirected catchall email sent to anyone@mysite.com looks like with a quick hack to grab the last for (original) target (2) and the To: field (3) - the (n) are added for clarity. There are some mail Parsers on CPAN that you should look at but as you will have to do the guestimations by hand this may just do. You could use something like String::Approx to automatically guess the best address.

    my $message = join'',<DATA>; my ( $for, $to ) = $message =~ m/.*for\s+<([^>]+)>.*\nTo:\s+([^\n]+)/s +; print $for, $/, $to; __DATA__ Return-Path: <jfreeman@tassie.net.au> Received: from zeus.tassie.net.au (zeus.tassie.net.au [203.57.213.21]) by perseus.tassie.net.au (8.12.2/8.12.2/RG2.2) with ESMTP id g +3IB9LuQ085226 for <jfreeman@tassie.net.au>; Thu, 18 Apr 2002 21:09:21 +1000 +(EST) Received: from perseus.tassie.net.au (perseus.tassie.net.au [203.57.21 +3.25]) by zeus.tassie.net.au (8.8.8/8.8.8) with ESMTP id VAA16087 for <anyone@mysite.com(1)>; Thu, 18 Apr 2002 21:10:26 +1000 (E +ST) Received: from tassie.net.au (dialin67.hbt.tassie.net.au [203.57.210.6 +7]) by perseus.tassie.net.au (8.12.2/8.12.2/RG2.2) with ESMTP id g +3IB9KuQ085223 for <anyone@mysite.com(2)>; Thu, 18 Apr 2002 21:09:20 +1000 (E +ST) Message-ID: <3CBEAB8D.A7CD69BC@tassie.net.au> Date: Thu, 18 Apr 2002 21:18:37 +1000 From: James freeman <jfreeman@tassie.net.au> Organization: Adajio X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en,pdf MIME-Version: 1.0 To: anyone@mysite.com (3) Subject: redirect Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mozilla-Status: 8001 X-Mozilla-Status2: 00000000 X-UIDL: lL`"!A@*!!#/'#!RO3"! This message will get redirected to catchall because anyone is not a valid account at mysite.com

    cheers

    tachyon

Re: Routing mail collected from a POP3 Server
by Biker (Priest) on Apr 18, 2002 at 14:00 UTC

    When I look into the spam I receive, it seems very common that they use X-Reciept: to indicate my real and valid e-mail address, whereas the To: can, as you already pointed out, contain just anything.

    Try that and see if it fits your needs.


    Everything went worng, just as foreseen.

Re: Routing mail collected from a POP3 Server
by asiufy (Monk) on Apr 18, 2002 at 16:09 UTC
    Have you checked with the people that host your domain if they won't allow for POP3 account aliases? That way, you could have freddie@yourdomain.com and fredie@yourdomain.com point to the same POP3 mailbox.

    You can still write something to check that 'catchall' account, but make it so it just warns you of new 'typos' and aliases that you should add.
Re: Routing mail collected from a POP3 Server
by wmono (Friar) on Apr 18, 2002 at 17:12 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://160165]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-09-20 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (155 votes), past polls