5

I'm trying some sort of auto-subscription via a homegrown script. I know it can be achieved by mailing lists such as Mailman but I also want to learn at the same time on how to do it by hand.

Here's the simple script:

#!/usr/bin/perl

use strict;
use warnings;

open ("RCV_MAIL", ">>/home/icasimpan/mail_received.txt") or die $!;
while(<STDIN>){
   print RCV_MAIL;
}
close(RCV_MAIL);

I attached the above script in /etc/aliases using the syntax:

subscribe: | /home/icasimpan/parse-subscribe.pl

and run

$ sudo newaliases

It's still a very bare script. Just testing out if I my syntax in /etc/aliases is correct.

But when I tried emailing subscribe@mydomaintests.tld, it returns something like:

Delivery failure 69

I'm using Lotus Notes so my google search directed me to this link. Apparently, something to do with the file...Not sure.

The command is executable, in fact I tried making it 777 and even created the mail_received.txt in the directory just to ensure I have no file permission problem but still the same.

Can anyone pitch in please?

Thanks in advance.

  • Side note: I also tried my script from command line and it works....$ echo "CLI Test"|./parse-subscribe.pl and I could get the "CLI Test" inside mail_received.txt – icasimpan Jan 28 '11 at 3:16
  • Temporarily made /home/icasimpan 777 just to rule out permission problems but still the error is the same. – icasimpan Jan 28 '11 at 3:23
4

If you're running a sendmail with smrsh set up (common in a lot of default configurations) you will need to run the piped command out of /etc/smrsh/. It can either be a symlink or a copy of the script, but if sendmail has 'smrsh' defined, it will need to be run from that directory. For example:

subscribe: | /etc/smrsh/parse-subscribe.pl

Check the sendmail documentation on smrsh for more details.

  • Haha, this works. Thank you so much! :) – icasimpan Jan 31 '11 at 0:36
3

You need to quote the "alias" if it has a space in it:

subscribe: "| /home/icasimpan/parse-subscribe.pl"

or remove the space:

subscribe: |/home/icasimpan/parse-subscribe.pl
  • This has been helpful to me too. Thank you :) – icasimpan Jan 31 '11 at 0:37
-1
open ("RCV_MAIL", ">>/home/icasimpan/mail_received.txt") or die $!;
while(<STDIN>){
   print RCV_MAIL;
}

is wrong.

If you're trying to print lines from STDIN to mail_received.txt, you would need:

open (RCV_MAIL, ">>/home/icasimpan/mail_received.txt") or die $!;
while (<STDIN>) {
   print RCV_MAIL $_;
}

because print with one argument takes the argument to mean the list to print, not the filehandle to print it to.

$ perldoc -f print
print FILEHANDLE LIST
print LIST
...

Also, no need for quotes around the filehandle name in open. Just use RCV_MAIL.

  • Thanks for the suggestion Mikel but it doesn't seem to work. I tried print $_ RCV_MAIL; or print RCV_MAIL $_; but no luck... – icasimpan Jan 28 '11 at 8:19
  • Hmmm. Could that be a typo error? I don't see a < in this perl reference perlfect.com/articles/perlfile.shtml – icasimpan Jan 28 '11 at 8:32
  • Sorry, my last comment was wrong. Please ignore it. – Mikel Jan 28 '11 at 8:32
  • open("RCV_MAIL", …) is horrible style, but it does work (Perl converts the string to a symbol). print RCV_MAIL works as well (it's a FILEHANDLE followed by an empty LIST, this only works if FILEHANDLE is a bare word IIRC). – Gilles Jan 28 '11 at 20:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.