Back To The Main Support Page
E-Mail Handling and Processing
Slingshot Hosting Servers are by default setup to handle simple e-mail setups. If you're looking to have all the bells and whistles of a fully functioning e-mail server with POP3/IMAP/SMTP-AUTH, you may add this functionality to your server yourself (guide here), however, we recommend simply using a mail server for mail and a Rails application server for Rails applications. Below you'll find the simplest ways to handle mail, including forwarding and processing.
Contents
Simple Mail Handling
Incoming Mail Processing
Simple Mail Handling
To create a forward so that mail sent to your server is forwarded somewhere else, simply add a user and edit their .forward file.
daytona # useradd -m -G users -s /bin/bash bobjones daytona # cd /home/bobjones daytona # nano .forward
The forward file can simply list e-mail addresses that you'd like to forward to:
bobjones@gmail.com bobby_jones29@hotmail.com
Incoming Mail Processing
First, ensure you're running either postfix or qmail. Skip down to the appropriate instructions for postfix below if you're using our newest image.
Forwarding mail to Rails ActionMailer with qmail
There are lots of ways to do it, but here’s an easy one.
First, ensure that normal mail delivery occurs.
Now, let’s create the user/email to be our action mailer address, for example the email ruby-mail@highgroove.com will pipe to our ruby runner:
daytona $ useradd -m -G users -s /bin/false ruby-mail
This adds a user with no abilities to login, just sets up a “home” directory for them.
You can view it at /home/ruby-mail
Next, let’s change the default deliver to a .maildir directory to pipe to our program. With qmail, we simply edit the .qmail file in the ruby-mail directory:
daytona $ vi /home/ruby-mail/.qmail
and put in one line:
| /usr/bin/ruby /path/to/app/script/runner
To test this you can use the following one-liner instead:
| /bin/cat > /tmp/test.txt
Which simply drops any email sent to ruby-mail@highgroove.com to a test.txt file in the tmp directory. So, as long as you’ve got the pipe correctly done and your ruby script is taking in the input from STDIN, you should be fine.
Since we do have procmail, another way is to change the .qmail to read:
| /usr/bin/procmail
And then we could add a .procmailrc file to /home/ruby-mail to do all kinds of procmail rules to deliver (like the Agile Web with Rails book has as an example—subject line matching etc.)
Alternatively we could even make the .procmailrc part of the code for the web app if it got kind of hairy and then setup a symlink to it:
| /usr/bin/procmail /path/to/app/config/procmail_rules
Forwarding mail to Rails ActionMailer with Postfix
The easiest way to forward mail from postifix is to setup a new alias.
First, create an alias on the machine, for example: "rails-mail" and add it like to your aliases file located in /etc/aliases
rails-mail: "|/path/to/app/script/runner 'Mailman.receive(STDIN.read)'"
Any time you update the aliases file, you must run the command: newalises.
newaliases
If you are using virtual hosts in Postfix, you need to inform Postfix that incoming emails of a given address should be forwarded to this alias by adding a line below to /etc/postfix/virtual:
/^.*@.*example.com$/ rails-mail
make && make install
Your ActionMailer should work now. To test, you can simply setup a handler that outputs to a file. In your aliases file, put the line:
rails-mail: "|cat /tmp/incoming_mail.txt"
All your incoming mail will now be put into a file /tmp/incoming_mail.txt for testing purposes
We recommend against configuring Postfix to handle all mail for a domain, because of the sheer volume of spam and spam bounches (not even your own) that will clog up your mailer over time, but if you would like to do this, see the Official Rails Wiki page on HowToReceiveEmailsWithActionMailer, as we contribute to this guide from time to time.
See also: Deploying Your Application to Slingshot using Capistrano