Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I painlessly receive mail in linux and feed it to Rails?

I've been googling all night for postfix howto's, but still I couldn't figure out how do I manage to receive email on linux-server (being more specific - Ubuntu).

All I need is a catch-all mailbox which gets all emails and feeds them to the ruby script (which then passes it to Rails, of course). I was able to set-up postfix for sending emails a while ago and I have to say - it wasn't painful at all, I did almost nothing besides actually installing it.

Could you suggest a good howto, or a recipe, or an alternative easy-to-setup mail-server that could solve the issue?

like image 701
snitko Avatar asked May 24 '09 00:05

snitko


People also ask

How do I read mail in Linux?

prompt, enter the number of the mail you want to read and press ENTER . Press ENTER to scroll through the message line by line and press q and ENTER to return to the message list. To exit mail , type q at the ? prompt and then press ENTER .

Where is Unix mail stored?

Incoming mail is stored in the system mailbox. By default, a user's system mailbox is a file located in the /var/spool/mail directory. The mailbox file is named after the userID. For example, if your user ID is jeanne, then your system mailbox is /var/spool/mail/jeanne.

How can I tell if an email is configured in Linux?

Type "ps -e | grep sendmail" (without quotes) at the command line. Press the "Enter" key. This command prints a listing that includes all running programs whose name contains the text "sendmail." If sendmail is not running, there will be no results.


1 Answers

Choose the account you wish to receive mail that is forwarded to your Ruby script. Edit the .forward file in the home directory of that script to read

"|/path/to/my/ruby/script"

When postfix delivers mail to the account, it will run the script with the permissions of the designated user and will provide the mail on standard input. Depending on what you do with the mail you may want to authenticate it in some way so that the script knows it is really from you. (E.g., header with salt and SHA1 hash of salt+password.)

Here's a real-life example from my own hairy mail system:

"|/home/nr/bin/filtermail /home/nr/machine/x86-bsd/bin/luapipe /home/nr/machine/x86-bsd/bin/safe-slocal 2>>/home/nr/slocal.log 1>&2"

This goes to a shell script which then calls both Lua and C programs to dispose of mail properly.

like image 65
Norman Ramsey Avatar answered Oct 05 '22 04:10

Norman Ramsey