Gossamer Forum
Home : General : Perl Programming :

Piping an email...

Quote Reply
Piping an email...
Has anyone had much experience with this? At the moment, I'm using this, as an email forwarder;

| /usr/bin/perl /home/ace-ins/public_html/dev2/pipe.pl

I've also tried;

| /home/ace-ins/public_html/dev2/pipe.pl

| perl /home/ace-ins/public_html/dev2/pipe.pl


I just keep getting this error;

pipe to |/usr/bin/perl/home/ace-ins/public_html/dev2/pipe.pl
generated by testpipe@ace-installer.com
Child process of virtual_address_pipe transport returned 69 (could mean service or program unavailable) from command:
/usr/bin/perl/home/ace-ins/public_html/dev2/pipe.pl

This is the code I'm currently using...it just seems to hang from SSH;

Code:
@email_in = <STDIN>;

foreach (@email_in) { $data .= $_; }

$sendmail = "/usr/sbin/sendmail";
$email = "webmaster@ace-installer.com";
$subject = "Email grabbed...";

open(MAIL, "|$sendmail -t -i") || die &error;
print MAIL "To: $recipient \n";
print MAIL "From: $email \n";
print MAIL "Reply-to: $email \n";
print MAIL "Subject: $subject \n\n";
print MAIL "Data: $data\n";
print MAIL "$send\n";
print MAIL "\n";
close(MAIL);

Anyone got any ideas? As I say, this is the first time I have played with piping from an email, so I'm pretty clueless on it all Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Piping an email... In reply to
Why are you piping an email to a script that just resends the email?....it would be far simpler to just forward it on to your other account.
Quote Reply
Re: [Paul] Piping an email... In reply to
That is just a test script, so I can see what data is being sent via <STDIN>. Once I know how its formatted, I'm going to do some parsing, and eventually write it into a mailing list database.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Piping an email... In reply to
Who's $recipient?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Piping an email... In reply to
Ah...now thats WHY I should have used strict Tongue

I ended up using;

Code:
#!/usr/bin/perl

use strict;

my @data = <STDIN>;

my $data;
foreach (@data) { $data .= $_; }

my $sendmail = "/usr/sbin/sendmail";
my $email = 'webmaster@ace-installer.com';
my $subject = "Email grabbed...";

open(MAIL, "|$sendmail -t -i") || die "Error: Can't send email. Reason - $!";
print MAIL "To: $email \n";
print MAIL "From: $email \n";
print MAIL "Reply-to: $email \n";
print MAIL "Subject: $subject \n\n";
print MAIL "Data: $data\n";
print MAIL "\n";
close(MAIL);

That emailed the following data to me;

Quote:
Data: From webmaster@ace-installer.com Fri Mar 21 10:51:57 2003
Received: from dial-62-64-216-6.access.uk.tiscali.com ([62.64.216.6] helo=y7u8a3)
by host13.imagelinkusa.net with esmtp (Exim 3.36 #1)
id 18wOoG-0005JP-00
for pipe3@ace-installer.com; Fri, 21 Mar 2003 10:51:56 -0500
From: "Andrew Newby" <webmaster@ace-installer.com>
To: <pipe3@ace-installer.com>
Subject: sojkgdg
Date: Fri, 21 Mar 2003 15:50:08 -0000
Message-ID: <002b01c2efc1$8da7b4a0$f4f2fea9@y7u8a3>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_002C_01C2EFC1.8DA7B4A0"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.2627
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600

This is a multi-part message in MIME format.

...etc.

That mainly what I needed to see. Now I know I can use some regex to grab the FROM: part .. Smile

Thanks guys for the help.

BTW: Although I still get the email.. I get a bounced email too....containing;

Quote:
This message was created automatically by mail delivery software (Exim).

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/ace-ins/public_html/cgi-bin/pipe.cgi
generated by pipe3@ace-installer.com

The following text was generated during the delivery attempt:

------ pipe to |/home/ace-ins/public_html/cgi-bin/pipe.cgi
generated by pipe3@ace-installer.com ------

test
------ This is a copy of the message, including all the headers. ------

Return-path: <webmaster@ace-installer.com>

...etc.

Do you know how I would get around this? Maybe setting up an email, and sending the actual data to /dev/null?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Piping an email... In reply to
You can get around it by not using Exim Wink

Btw,

Code:
my $data;
foreach (@data) {
$data .= $_;
}

...why not:

Code:
my $data = join "", @data;

Last edited by:

Paul: Mar 21, 2003, 8:47 AM
Quote Reply
Re: [Paul] Piping an email... In reply to
Yeah, I don't have control over what mail stuff I use Tongue I'm on managed hosting now, remember? ;)

Anyways..I managed to get around it by adding a forward to the script (with a pipe), and then setup an account going to /dev/null/ too :)

BTW: Is this code correct?

$_ =~ /From: \"(.+?)\" \<(.+?)\@(.+?)\>/i;

I want to grab the name between the ""s and also the stuff before and after the @ sign. For some reason, its just returning;

$1 = blank
$2 = blank
$3 = blank

and

$1 = t (subject was 'test'..so I'm assuming it was just grabbing the first work)

I'm confused as to why that regex doesn't work. I've used similar code in other Perl scripts, and it seems to have worked then Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Piping an email... In reply to
Whoops...got it working. I didn't realise I was re-definining the variables a little bit further down Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Piping an email... In reply to
You are using unnecessary escaping in your regex. You only need to quote meta-characters, eg +, ^, $, *

As for the from address, are you grabbing it to send an email to that person?...if so you should be able to grab the whole thing and set it as the from address in the email...you don't need to parse it.

If you do want to parse it, try:

Code:
/From:\s+"([^"]+)"\s+<([^@]+)@([^>]+)>/

...not all emails will be in the format:

"Name" <email>

...so be aware of that. You may want to consider MIME::Parser