Re: [PHP-DB] Reading emails with PHP
Manuel, et al -- ...and then Manuel Lemos said... % % Hello, Hi! % ... % A more useful solution is one based on setting the return path address % of the message being sent in such a way that you can retrieve the % original recipient address from the bounced message recipient address. Agreed. Full VERPing can be done if the client is interested :-) % % This has just been discussed here: % % http://marc.theaimsgroup.com/?t=1071585r=1w=2 Thanks! % % -- % % Regards, % Manuel Lemos HAND Happy Holidays :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP-DB] Reading emails with PHP
Hello, On 12/19/2003 09:54 AM, David T-G wrote: OK, so on to the script. Just as PHP has classes, perl has modules which implement object code. Just as PHP has PEAR (I think; I'm still getting to know it), perl has CPAN, the Comprehensive Perl Archive Network. One advantage of perl's maturity is an almost ridiculously vast wealth of contributed modules; if you want to do it, someone has almost certainly already written a module for it. [This is already on the way for PHP and PEAR; in just a few years I, too, predict that PHP will be hugely popular.] The one used here is Mail::DeliveryStatus::BounceParser. This solution has two significant limitations: 1) Many bounces will not be returned as delivery status messages 2) Many users may be register with e-mail addresses which are just forwarding addresses, so the address returned by the report specifies the final address and not the actual address of subscription. A more useful solution is one based on setting the return path address of the message being sent in such a way that you can retrieve the original recipient address from the bounced message recipient address. This has just been discussed here: http://marc.theaimsgroup.com/?t=1071585r=1w=2 -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Reading emails with PHP
It may be sacrilege to mention it here, but there is an excellent perl module for handling mail bounces; I've used it to write a handler that catches the returned mail, gets the address(es) and reason(s) for the bounce, and then goes into our DB and flags the matching users. I looked all around at the time (this summer) but saw no php code like it, so I overrode my client's desire for PHP with his desire for savings :-) I'd be interested in more details on this, from the pov of a person who primarily knows php and only dabbled in perl, as I've never got anything to work in Perl. Do I envisage a .pl file on the server, is there a reference to this near the mail() php sending function etc... who does it tie together. Can the mail be first sent with mail() or does it have to be sent with a perl mail function? If the answer is too perl-intensive then reply off-group but I think it is of interest to php beginners to know what the alternatives are and how they might be dipped in and out of. http://www.cantor.com CONFIDENTIAL: This e-mail, including its contents and attachments, if any, are confidential. If you are not the named recipient please notify the sender and immediately delete it. You may not disseminate, distribute, or forward this e-mail message or disclose its contents to anybody else. Copyright and any other intellectual property rights in its contents are the sole property of Cantor Fitzgerald. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. Although we routinely screen for viruses, addressees should check this e-mail and any attachments for viruses. We make no representation or warranty as to the absence of viruses in this e-mail or any attachments. Please note that to ensure regulatory compliance and for the protection of our customers and business, we may monitor and read e-mails sent to and from our server(s). For further important information, please read the Important Legal Information and Legal Statement at http://www.cantor.com/legal_information.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Reading emails with PHP
John, et al -- ...and then Dillon, John said... % % It may be sacrilege to mention it here, but there is an excellent perl % module for handling mail bounces; I've used it to write a handler that ... % % I'd be interested in more details on this, from the pov of a person who No problem. % primarily knows php and only dabbled in perl, as I've never got anything to Heh. If you can't get a helloworld working we should probably take things one step at a time :-) But don't worry; I can help you a bit and there are excellent perl lists just like these excellent php lists exist. % work in Perl. Do I envisage a .pl file on the server, is there a reference % to this near the mail() php sending function etc... who does it tie % together. Can the mail be first sent with mail() or does it have to be sent Let's back up a moment... The original request was for a way to go through a stack of mail bounces to pull out the intended addressee and the reason for the bounce. My need was to handle bounces as they came in, ascertain the same thing, and then go and update my DB. In either case, the mail was sent long ago and is completely separate from handling the incoming (or present) bounce. It doesn't matter what sort of mail function you use; it can be sent via morse code over a 110baud modem if you like :-) % with a perl mail function? If the answer is too perl-intensive then reply % off-group but I think it is of interest to php beginners to know what the % alternatives are and how they might be dipped in and out of. OK, so on to the script. Just as PHP has classes, perl has modules which implement object code. Just as PHP has PEAR (I think; I'm still getting to know it), perl has CPAN, the Comprehensive Perl Archive Network. One advantage of perl's maturity is an almost ridiculously vast wealth of contributed modules; if you want to do it, someone has almost certainly already written a module for it. [This is already on the way for PHP and PEAR; in just a few years I, too, predict that PHP will be hugely popular.] The one used here is Mail::DeliveryStatus::BounceParser. Once we set up the script to use the module with ### basic setup ## {{{ use strict ; # watch your knuckles! use warnings ;# only slightly kinder use DBI ; # talking to a database use DBD::mysql ; # what kind of database? use Mail::DeliveryStatus::BounceParser ; # parsing magic ## }}} catching the mail is literally as easy as ### catch the input ## {{{ my $bounce = eval { Mail::DeliveryStatus::BounceParser-new ( \*STDIN ) } ; if ( $@ ) { print Whoa -- one we actually couldn't handle!\n ; exit 255 ; } ## }}} and then, once we make the DB connection, handling the message is also as easy as ### loop thru the message ## {{{ foreach my $report ( $bounce-reports ) # loop thru reports for each addr in the bounce { ### I'd love to grab the *current* M-ID: here... maybe someday my $orig_mid = $bounce-orig_message_id;# my $email = $report-get('email') ; # bouncing address my $std_reason = $report-get('std_reason') ; # why my $reason = $report-get('reason') ; # other why my $date = $report-get('arrival-date') ; # bounce date my ($sec,$min,$hour,$mday,$mon,$year) = localtime ; $year += 1900 ; $mon++ ; $date = $date ? $date : $year-$mon-$mday ${hour}:${min}:$sec ;# be sure we have a date $ur-execute($email) ; # update user record $br-execute($email,$std_reason,$reason,$orig_mid,$date) ; # update bounce log } ## foreach(@reports)## }}} and we're done! The hardest part was figuring out that I had to loop through $bounce-reports because it wasn't clear in the man page for the module *blush*. Back, for a moment, to the DB connection... perl lets you set up or prepare multiple connections and queries in advance, and then you just feed one the data for that iteration and off you go. That's what $ur and $br are above, and the connection piece that I glossed over looks like ### make DB connection## {{{ my $drh = DBI-install_driver(mysql)# talking mysql or die(Cannot install mysql driver!\n) ; my $eteam = $drh-connect(##DBNAME,##DBACCT,##DBPASS,{AutoCommit = 1}) # hook up or die(Cannot connect to database server!\n) ; ### prepare query my $u = update eteam.USER set FLAG_CONFIRM = 2 where EMAIL = ? ;# user status query my $b = insert into eteam.MAIL_BOUNCE values (?,?,?,?,?) ; # bounce mail log query my $ur = $eteam-prepare($u) ;# prepare query (user) my $br = $eteam-prepare($b) ;# prepare query
Re: [PHP-DB] Reading emails with PHP
John, et al -- [We're going to talk about perl a bit more, albeit comparing and contrasting with php. If this should be kicked off of the list, just let us know.] ...and then Dillon, John said... % % As one who has used php (without classes) but has seen cpan in operation % (I'd describe it as connecting to the internet from the c: prompt, if using Heh :-) Not a bad analogy, though it leaves a lot out. % Windows) and it's impressive though complicated, only the documentation is a % bit flat on perl and beginners lists require you to have memorised Learning Now, now... I'd hesitate to call the perl doc flat; I haven't even read it all and I've been playing with perl for years! There is a *lot* of documentation available just with the standard perl installation. % Perl to understand the answers... I got flamed for mentioning php on a perl *rofl* Yes, an expectation of having read some background is there. It's not nearly so bad as on the DJB utils lists, though! % beginners list, so I hope php people are not so religious. Though this is How interesting... The [EMAIL PROTECTED] list isn't religious and it would certainly be safe to mention php in an on-topic post there; where and what did you mention? Of course, if you came in and started shooting off about how php was great and did this and that and perl just sucked then, yeah, you might get flamed -- on any list :-) % about perl it is a php-background web person trying to understand it. Right. % % The one used here is Mail::DeliveryStatus::BounceParser. % % Where does the perl module reside on the server? I have my home space, so I You could put it in your personal perl library or the server perl library. In this case I had root access and was installing for the machine owner and so I put it in /usr/lib/perl5/... % have seen modules attempting to download onto my computer but would not know % about doing it on my host server. Perhaps it is preinstalled on the server Right. I wouldn't, either; although there are undoubtedly ways to ftp into place a module's pieces I've only ever installed from a shell prompt. I suppose you could write a script to do the install and call it from a web page :-) % (a standard module) or I just need to contact my host provider. You should be able to ask them to install it for you. % % Once we set up the script to use the module with % % This I understand - the below lines are written in a plain text file and % saved as a .pl file. Yep. % % ### basic setup## {{{ ... % use Mail::DeliveryStatus::BounceParser ; # parsing magic % ## }}} % % catching the mail is literally as easy as % % ### catch the input## {{{ % my $bounce = eval { Mail::DeliveryStatus::BounceParser-new ( \*STDIN ) } % ; % if ( $@ ) % { % print Whoa -- one we actually couldn't handle!\n ; % exit 255 ; % } ## }}} % % Sorry, lost. What wakes up this file to notice that an email has bounced That's the .qmail/.forward thing, so we'll cover it below. % and execute the second line? Is it its location on the server? How does it It can be located anywhere as long as the MTA/MDA (Mail Transport Agent and/or Mail Delivery Agent) is told where to go and find it. Mine is way away from the home dir of the account calling it. % realise it has some input, STDIN, to look at? (Is there a similar concept % to STDIN in php?) When I'm whipping out a one-liner to test an example I'm usually lazy and just use echo '...' | php -q and so that's one way. I actually don't know how to do the equivalent of perl -e 'print hello, world\n ;' which then leads to echo hello, world | perl -e 'print STDIN ;' in php, so actually passing stdin to a script is a good question. Perhaps fopen(php://stdin,'r') ; or such as shown in the manual. Oh, wait -- STDIN is an already-defined constant that is the same thing, so you just use it :-) But I still don't know how to build a script on the command line to use that... % % through $bounce-reports because it wasn't clear in the man page for the % module *blush*. % % For those new to perl, I got as far as % http://www.perldoc.com/perl5.8.0/pod/perl.html and couldn't find the man You won't; it's not a stock part of perl but an add-on module. % page for the module. (I've never been lost in php.net.) The fact that Well, could you find the docs for HTML_Client in the php.net php docs? You'd no doubt at least have to go over to pear.php.net but very probably have to pull down the tarball, just like with the BounceParser module. % $bounce-reports gives a $report would be because the object $bounce from: % my $bounce = eval { Mail::DeliveryStatus::BounceParser-new ( \*STDIN ) } ; % % has a 'report' method defined in the module. The module documentation Well, a 'reports' (plural!) method, anyway. My problem was that I didn't realize I was getting back an array of reports and would need to loop over it. % should tell us
Re: [PHP-DB] Reading emails with PHP
Chris -- ...and then Chris Payne said... % % Hi there everyone, Hi! % % A quick question, is it possible to read a failed mail email ... % % Any help, tips would be REALLY appreciated as I REALLY don't want to spend a few days doing it manually. It may be sacrilege to mention it here, but there is an excellent perl module for handling mail bounces; I've used it to write a handler that catches the returned mail, gets the address(es) and reason(s) for the bounce, and then goes into our DB and flags the matching users. I looked all around at the time (this summer) but saw no php code like it, so I overrode my client's desire for PHP with his desire for savings :-) % % Oh and Merry Christmas / Happy Holidays. And to you! % % Chris HTH HAND Happy Holidays :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature