Serving files from your e-mail account

From JoatWiki
Jump to: navigation, search

One of the nice things about this method is that you don't need an extra e-mail account to "autosend" files. It runs in-line as part of your existing e-mail account.

Please read the Procmail howto to figure out how to get Procmail filtering up and running. That is beyond the scope of this mini-howto. If you have the standard RedHat/Mandrake install, you'll probably only need to install Mail::Sender (Suggestion: use the cpan utility for an easier install.). (URL for Mail::Sender -> http://cpan.valueclick.com/authors/id/J/JE/JENDA/ )

It is assumed that you are running Sendmail or Postfix along with Procmail. I run a Sendmail/Procmail setup behind a very restrictive iptables configuration which allows only local connections. How do I get messages onto the server? Easy. I use fetchmail. But that's irrelevant for this document.

  • First install the Perl module, Mail::Sender (cpan users can type "install Mail::Sender")
  • Create a directory to contain your outgoing files in and populate it. Ensure sufficient permissions exist so that the local user can read the document.
  • Create a local "bin" directory in your home directory. Example: /home/tlk/bin
  • In the local bin directory, create a Perl program with the following code (or similar). Call it "filesender" or some such.
   #!/usr/bin/perl
    
   # grab the address and filename from the ARG array
   $address=$ARGV[0];
   chomp $address;
   $address=~ s/\s+//g;
    
   $filename=$ARGV[1];
   chomp $filename;
   $filename=~ s/\s+//g;
    
   # load the module
   use Mail::Sender;
    
   # set up the connection to the mail server
   $sender=new Mail::Sender {smtp => '127.0.0.1', from => 'joat@757.org'};
    
   # notify yourself that so-and-so has requested a file
   $sender->MailMsg({to => 'joat@757.org', subject => 'File request', msg => "$address has requested file $filename"});
    
   # send the file
   $sender->MailFile({to => "$address", subject => 'Requested file', msg => 'Attached is the file that you requested from joat@757.org', file=>"/home/tlk/files/$filename"});
    
   # end of program

Note: see how that last line wraps immediately after ".net" in the MailFile line? There's an actual CR there. For some reason the Mail::Sender module delimits various items before processing it and \n's are lost. (If anyone comes up with a fix, let me know?)

  • Add the file serving recipe to Procmail In your recipe file, add the following:
    :0
    * ^Subject:.*send file list
    {
    	:0                    # Use procmail match feature
    	* ^From:\/.*
    	{
    		FROM = "$MATCH"
    	}

    	:0 w
	|perl /home/joat/bin/filesender "$FROM" filelist.txt

    }

In the above, there are two parts to the action portions of the recipe. The first determines the address to send the file to and the second passes that variable to the file sending Perl script.

  • That's it. Test it. Send e-mail to yourself with the proper subject line. See if you're file is delivered properly. Keep any eye on your mail logs and Procmail logs to determine if everything is occurring correctly. Have a friend, with a different mail client, perform the same tests.

Security-wise, the above method is pretty benign. No passwords are used. Direct input of data from the user is not used. Only files that you filter for in Procmail are transmitted. Nothing is run as root.

A copy of my .procmailrc file is available by sending an e-mail to "joat@757.org" with the subject line of "send .procmailrc". (without the quotes) A list of other available documents can be requested via the same e-mail address by changing the subject line to "send file list".

- joat (09 Feb 2002)

[Note: this article is subject to change as I tweak things on my end.]

<comments>Serving_files_from_your_e-mail_account</comments>

Personal tools