Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Documentation for: mailserver.r

Usage document for %mailserver.r

1. Introduction to %mailserver.r

Ever wanted to run a mailing list server? This little gem could be the founding roots of a mailing list empire.

2. mailserver At a Glance

This script requires some setup to be useful, and cannot be run right out of the box.

3. Using %mailserver.r

There are two critical changes to start up your own mail list server.

First you need to change the group block. It is the list of email addresses included in the group. For a few addresses, this is fine. If you expand this script, you may want to place this information in an external resource and LOAD it, but you'll know what you are doing by then.

Please note the script header warning. The email address used to read mailing list entries cannot be specified in the group block, or an infinite loop occurs. This script will halt if it detects that condition.

The next step is to prepare an external %popspec.r.
Full details are found in the library under popspec.r 

You may also want to control the period of time between scans of incoming mail account. The last line of the scan loop is a wait native. By default, this is set to 10 minutes. You may find other timings more useful. Less time for a super busy list, more time for a list with less traffic.

Advanced users may even place the time! value in a variable and pace the scans by amount of traffic.

Once the two critical items are defined this utility is simple to use. Just DO it.

 >> do %mailserver.r
 $ rebol -qw mailserver.r&

will start rebol up in the background, freeing your terminal session for other use. Note, this is a GNU/Linux shell command example. A Windows(tm) short-cut icon could be used to accomplish much the same thing.

You now have the mailserver running and waiting to receive and forward mail.

Note you cannot execute %mailsever.r right out of the library.

4. What you can learn

At least three important learning items in this script.

See how easy it is to load an email message? REBOL has builtin support for the POP network protocol and includes a routine to import this into a mail message object.

The nature of REBOL ports, in this case open by loading %popspec.r, allows traversing the inbox with series operations. The string form of a mail message is simply first inbox, but this could be last inbox or any other series operation. The mailserver routine loops over all incoming mail messages until tail? returns true. If the inbox is empty, tail? will be true, on the first pass.

Once again, full details on %popspec.r can be found in the library under popspec.r 

Next is the import-email function. It parse the mail message and returns a mail message object. A path specification allows easy access to the fields in this object. For this script, the mail/from/1 is scanned to see if it is from anyone listed in the group. If it is from a member of the group, the powerful RESEND function (which forwards a copy of the message), is called in a loop for each user in the group.

Mail messages destined for the group are then removed from the inbox, by simply using the series! remove function on the inbox port. All other messages are left as is.

This means they will left in the inbox for later retrieval. Perhaps this account is also your personal email account used for other emails. But it also means you will have to open the account from time to time to make sure there is not an accumulation of messages building up.

The mailserver then waits 10 minutes before scanning the through the inbox again.

5. What can break

A slow network connection may work against you. You may need to tweak system/schemes/default/timeout (REBOL has it set to integer! 30) or system/schemes/pop/timeout for the POP scheme can be set to an appropriate value (if none it uses system/schemes/default/timeout).

For a real-world mailserver, this script would need to be wrapped in a routine that restarts it on failover.

6. Credits

%mailserver.r Original author: Unknown
  • The Library Team
  • Usage document by Brian Tiffin, Library Team Apprentice, Last updated: 5-May-2007