简体   繁体   中英

Piping email to Perl script, but always gives back error message

I'm trying to figure out how to get this email piping to work in a script I'm doing. In CPanel, I have it setup to forward to:

Current Setting: |/home/user/public_html/cgi-bin/links/email-in.cgi

The script is really simple:

#!/usr/local/bin/perl

use strict;
use lib '/home/user/public_html/cgi-bin/links/admin';
use Links qw/$DB $IN $CFG/;
use CGI::Carp qw(fatalsToBrowser);
use Links;

Links::init('/home/user/public_html/cgi-bin/links/admin');

open (STDERR, ">>/home/user/public_html/cgi-bin/links/mail.log") || die $!;

my $message;
while (<STDIN>) {
    $message .= $_;
}

print STDERR qq|$message\n\n|;

close (STDERR);

print $IN->header;
print "FOO BAR";

Then sending a test email to that address, I correctly see the value of <STDIN> in email.log. However, a minute or so later, I get this email bounced back:

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

pipe to |/home/user/public_html/cgi-bin/links/email-in.cgi generated by foo@resa.site.org

The following text was generated during the delivery attempt:

------ pipe to |/home/user/public_html/cgi-bin/links/email-in.cgi generated by foo@resa.site.org ------

Content-type: text/html; charset=iso-8859-1

FOO BAR Action: failed Final-Recipient: rfc822;|/home/user/public_html/cgi-bin/links/email-in.cgi Status: 5.0.0

I'm a bit confused as to why its doing that. Do I need to return a specific header, or something like that? (to tell the email program that its been properly processed)

Eugh, I knew this would happen! Literally as soon as I posted, I found the answer here:

https://confluence2.cpanel.net/display/ALD/Forwarders#Forwarders-PipetoaProgram

If your script produces any output, even a blank line, the system will create a bounce message that contains that output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM