LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2004, 01:36 PM   #1
ejy2
LQ Newbie
 
Registered: Jun 2004
Location: San Francisco
Distribution: Red Hat
Posts: 5

Rep: Reputation: 0
piping mail into a program


I'm trying to set up an auto-forwarding system, in which the following happens:
a) user A and user B have actual email addresses A and B and forwarding addresses C and D. This info is stored in the mySQL database of my site.
b) users A and B know each others forwarding addresses through the site, but no one knows anyone's actual email address.
c) user A, from his actual email account, sends a message to user B's forwarding address.
d) site's mail server receives the email. a program alters the email's header line so that the recipient address is changed to user B's actual email address B, and the sender's address is changed to user A's forwarding email address C. Anonymity is therefore preserved.
e) changed email is now put in the mailing queue and sent off.

I'm a linux beginner, and have just managed to make a test server which successfully receives and sends email from the root account. Using advice from other sites, I've done the following:

a. changed /etc/mail/virtusertable and added the following line:

admin@mydomain.com root
@mydomain.com remailer-alias

b. changed /etc/aliases and added the following line:

remailer-alias: |remailer

The idea is all non admin@mydomain.com emails should be piped into the remailer program. The remailer program should reedit the message and place it in the queue.

The problem is, I'm not sure how to write the remailer program or where to place it. I have written only extremely basic shell scripts or Perl programs, and in particular have not written a program that processed piped information, having used pipes only on the command line. I have tried to make remailer programs just to test the above functionality, for example:

#! /usr/bin/perl -w
# test remailer program in perl
print "hello!\n";

or using a shell script:

#! /usr/bin/sh
# test remailer program, shell script
echo "hello"

I changed the /etc/aliases line to:

remailer-alias: |/etc/mail/remailer

I then placed the remailer file into /etc/mail, chmod-ed it a+rx, and send myself an external email. The email either was bounced or was eaten up. I was hoping that a "hello" would appear to indicate the program was triggered when an email arrived.

My main question is: how do I go about writing the remailer program? Can I write it in Perl, or must I do it in a different language? Do I have to change config files somewhere to make this work? What is a good resource, either online or a book, that would help me become an expert in writing the kind of program that I want, particularly a program that can processed piped in information?

I think if I could get the email to trigger, say, a Perl program, I could probably figure out much of the rest. Its the initial triggering in and of itself that causing me a lot of problems.

Lastly, I do wonder: is this system robust enough to handle, for example, 100-500 forwarded emails a day?

Thanks so much for your help!
 
Old 06-22-2004, 01:58 PM   #2
Gnuru
Member
 
Registered: Jan 2004
Posts: 53

Rep: Reputation: 15
Yes, you can do it with perl. Go to CPAN and look at Mail::Mailer or Mail::Header to manipulate headers. You can either then pipe the message directly to sendmail or send it using Mail::Mailer. Perl also allows you to easily access the mySQL db using the DBI module.

Alternatively, you could do it with bash. Pass the message to formail which allows you to manipulate headers and then pipe them back to sendmail.
 
Old 06-22-2004, 04:26 PM   #3
ejy2
LQ Newbie
 
Registered: Jun 2004
Location: San Francisco
Distribution: Red Hat
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks! but still problems...

I appreciate your comments. I went to cpan.org and downloaded MailTools -- it seems to be the most reliable and popular Perl module for processing email. And I followed the instructions and installed it successfully.

I think I'm still having a problem, though, in getting an incoming email to pipe directly it any program that I am writing. Currently here is my setup:

/etc/mail/virtusertable:

[added] @mydomain.com remailer-alias

/etc/aliases:

[added] remailer-alias: |/etc/mail/remailer.pl

/etc/mail/remailer.pl

[contents of file]
#! /usr/bin/perl -w
use Mail::Internet
$message=new Mail::\*STDIN;
print $message;

The file runs fine, say, with a command line ls | remailer.pl.

However, when I send an email to my site, it just gets bounced. I was hoping that it would print the message. Somehow, the piping isn't working, but I can't figure out why. Do you have an idea?

When I alter the /etc/aliases file to reroute remailer-alias mail into root, the root account safely receives the mail. So it's not a problem with the mail getting through the firewall or something.

I really appreciate your help. Thanks!
 
Old 06-23-2004, 03:42 AM   #4
Gnuru
Member
 
Registered: Jan 2004
Posts: 53

Rep: Reputation: 15
What's the bounce/error message that sendmail is giving you?
 
Old 06-23-2004, 10:12 PM   #5
ejy2
LQ Newbie
 
Registered: Jun 2004
Location: San Francisco
Distribution: Red Hat
Posts: 5

Original Poster
Rep: Reputation: 0
Here's the text I get in the bounced email. The email was sent from Yahoo Mail to my home server. The virtusertable directs all domain mail to the remailer-alias, and the remailer-alias mail is directed using the aliases file line:

remailer-alias: |/usr/local/bin/mailstore.sh

/usr/local/bin/mailstore.sh is composed of the following:

#! /bin/bash
while read var_str;
do echo $var_str >> /tmp/test_out.txt
done;

I would expect, when outside mail comes in, that I would get a growing test_out.txt file in /tmp. Instead, the email is bounced, with the following error message embedded:

The original message was received at Wed, 23 Jun 2004 19:54:27 -0700
from web41704.mail.yahoo.com [66.218.93.121]

----- The following addresses had permanent fatal errors -----
|/usr/local/bin/mailstore.sh
(reason: Service unavailable)
(expanded from: <blabla@64.36.78.186>)

----- Transcript of session follows -----
smrsh: "mailstore.sh" not available for sendmail programs (stat failed)
554 5.0.0 Service unavailable

Thanks so much for inquiring, I'd appreciate any help you can give.
 
Old 06-23-2004, 10:35 PM   #6
ejy2
LQ Newbie
 
Registered: Jun 2004
Location: San Francisco
Distribution: Red Hat
Posts: 5

Original Poster
Rep: Reputation: 0
Figured it out thanks!

I figured it out, thank you for inquiring! I had to put a link file in /etc/smrsh or the file wouldn't run. I hope I can now run a Perl file, as that is my main goal, rather than just a bash script .... thanks, on to further adventures in Linux...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Piping to mail and adding a subject line. Echo Kilo Linux - General 1 12-03-2005 11:24 AM
Exim - piping mail sent to a particular address to a script Khang Linux - Software 2 01-31-2005 11:04 AM
mail using a C program linuxprogrammer Programming 5 07-21-2004 12:08 AM
The old mail program jeempc Linux - Software 3 10-14-2003 10:04 PM
Best mail program tabsnz Linux - Software 0 08-28-2003 03:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration