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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 05:08:17

问题


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?


回答1:


There are two parts to this answer, Norman Ramsey's answer covers the 2nd part: handing off the email to a script to be processed. The first part is configuring Postfix to receive the email. Since you need a catch-all you can put something like this in /etc/postfix/aliases

@yourdomain.com localuser

And 'localuser' is the name of the account on your system which has a

/home/localuser/.forward

which contains the command (see Norman's response). Or, you could keep it all in Postfix

/etc/postfix/aliases:

@yourdomain.com |/path/to/your/script

This will send all email that is sent to @yourdomain.com and sends it to your script for processing. Keep in mind that the script will be executed as the postfix user, so you will need to make sure your environment is setup appropriately (for instance you are not relying on a specific $PATH that your normal user account has). The postfix user likely has a very basic environment (e.g. might not even have /usr/local/bin in their $PATH)




回答2:


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.




回答3:


Also check out Jason Seifer's article for more details.

http://jasonseifer.com/2009/04/24/receving-email-with-rails



来源:https://stackoverflow.com/questions/902771/how-do-i-painlessly-receive-mail-in-linux-and-feed-it-to-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!