Discussion Lists

- Configuring mojo_send.pl
- Before You Set Up.
- Setup mojo_send.pl
- Configuring for Qmail
- Configuring for Sendmail
- CONFIGURING USING PROCMAIL
- Troubleshooting.
- How The Script Works
- A Word of Caution
- Special Commands Sent to mojo_send.pl
- COPYRIGHT

# Configuring mojo_send.pl

Mojo Mail can now send announce-only and group e-mails by using any e-mail program you normally use, instead of using your list's control panel. This is done by configuring mojo_send.pl. This script is located in the 'mojo' folder when you downloaded the script.

Note: These features may not be available to you. Not all hosting companies allow you take advantage of what Mojo Mail needs to get this setup. What you need to do is set up an alias e-mail address. An alias e-mail address is an address that goes somewhere else. You can have an address called ``bob@skazat.com'' that really goes to ``justin@skazat.com''. Instead of going to another address, we're going to tell it to go to a script - mojo_send.pl. The setup of this feature is NOT cut and dry.

Its hard to tell if you can do this at all and much banging of heads on desks might result. Please understand that all servers and mail programs are set up differently and I'm limited on what machines I can test this on. If you configure this script differently that whats written here, please share your findings to help others! Consider this script an advanced feature. As hard as this is, its factors easier than setting up something similar, like majordomo.

# Before You Set Up.

Before you go right into all of this, it might be a good idea to ask your system administrator if this is actually possible. You need to ask them if you are able to set up email addresses that alias to a file. You may not be able to. If you're server is using Sendmail, which is a very popular Mail User Agent, be aware that Sendmail can be configured to disallow mail aliasing to a program. You'll know if this can't be done if you get a 'Cannot send mail directly to a program.' error. Never hurts to ask!

I'll be giving you instructions on how to set up mojo_send.pl using qmail and sendmail. Most likely, you're using sendmail. I am not as familiar with sendmail as I am with Qmail.

# Setup mojo_send.pl

Open mojo_send.pl in your favorite text editor. You need to change one thing in that file. In the first part of the script, there's a line that says:

            $lib = '/usr/home/path/toyour/mojo_directory';

You have to change this to the directory that you put the mojo.cgi script and the MOJO folder. mojo_send.pl needs certain things in the MOJO folder to work correctly, so you need to tell it where it is.

Upload mojo_send.pl into your cgi-bin directory. For simplicity, upload it into the same directory as your mojo.cgi script and MOJO folder. Change the permissions of the script to 755, just like you did for the mojo.cgi script. If you want to, you may move this script in other places, for better security.

Making An Aliased E-mail address.

# Configuring for Qmail

Qmail uses a seperate '.qmail' file for each e-mail alias. An alias is called .qmail-alias, where 'alias' is your alias address. If I wanted bob@skazat.com to go to justin@skazat.com, I would make a .qmail file called

            .qmail-bob

and inside write this:

            &justin@skazat.com

which is the email address I want it to really go. Notice the Ampersand '&' character before the address. That's important. .qmail files are usually found in your home directory. My home directory is:

            /usr/home/justin

mojo_send.pl always looks for an address that's the same name as the list's short name with underscores instead of spaces. For the list short name, 'skazat design newsletter', i would want to make an e-mail alias 'skazat_design_newsletter@skazat.com'

To do this in Qmail, I would write a .qmail file called ``.qmail-skazat_design_newsletter'' and write:

            |/usr/home/pathtothe/mojo_send.pl

where '/usr/home/pathtothe/mojo_send.pl ' is the Absolute Path to the mojo_send.pl script. The vertical bar, '|' before the path is very important, it tells Qmail to pipe the message to the mojo_send.pl script, whos absolute pathname you specified after the vertical bar.

Test the script out by saving your mojo_send.pl changes and the .qmail file. Send a message to yourlist@yourdomain.com where 'yourlist 'is the name of your list's short name and 'yourdomain' is the name of your domain. Only the list owner and list administrator are allowed to send messages this way unless you specify that you want to have a group list. You can do this by going to the ``Mailing List Options'' screen of each list's control panel.

# Configuring for Sendmail

This particular set of instructions takes into account that you do have root access to the machine your using. If you do not have root access, these instructions will not work.

make an /etc/mail/aliases file, if you don't already have one and write in it:

            # My Mojo Mail List
            listname: "|mojo_send.pl"

where 'listname' is my list's shortname that I wanted to use. In 2.6, there are shortnames and list names, shortnames are kinda like login names, they're supposed to be short and lowercase, having a short name allows you to be more creative with the listname and also allows you to change the list name, which was a big request. Lists made with 2.5 below shortnames will be their original list names, which might not work correctly.

You may also need to tweak the virtusertable file in sendmail. For this example add this line:

     listname@mydomain.com          listname

You then have to issue this command:

     makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable

After that, make a directory for the sendmail restricted shell, if you don't already have one:

            sudo mkdir -p /usr/adm/sm.bin -m 755

In this directory, you list all the apps that you allow sendmail to run via pipes (like in my aliases file), for more info, type in

            man smrsh

in a telnet or ssh session

Make a soft link to mojo_send.pl:

            ln -s /Library/WebServer/CGI-Executables/mojo/mojo_send.pl
            /usr/adm/sm.bin/mojo_send.pl

Type:

            newaliases

in a telnet or ssh session for sendmail to see the new alias that you made and then restart sendmail

     Make sure in your sendmail.cf file (mine was in
    /etc/mail/sendmail.cf) has the alias file thingy uncommented, like this:

            # location of alias file
            O AliasFile=/etc/mail/aliases

Also, you want to set this to True:

            # use Errors-To: header?
            O UseErrorsTo=False

Sendmail sucks, don't it?

# CONFIGURING USING PROCMAIL

If your server has Procmail installed (and there's a good chance that it does) you can use it with mojo_send.pl, even if you can't configure Sendmail or Qmail.

Procmail uses 'recipes' to filter mail and send it to various locations. Here's a simple recipe for mojo_send.pl:

            :0
            * ^[TO|CC].*listname
            |/usr/home/pathtothe/mojo_send.pl

This recipe will look for any messages that are in the To: or Cc: headers and have listname in it.

Nothing to it. Obviously, this is not a lesson in Procmail, get Procmail working before trying this. A great tutorial on all this is at:

http://www.ii.com/internet/robots/procmail/qs/

More than you ever need can also be found here:

http://www.ii.com/internet/robots/procmail/

DO NOT ask me how to set up Procmail, I'm afraid I'm too green at it all. But here's some more info. Please understand that all this may be very local to the server setup I'm using. Anyways, for a list called 'info' I needed to setup a .qmail file called .qmail-info or the recipe would not work. my .qmail file looks like this:

            | preline /usr/local/bin/procmail -p

my .procmailrc file, among other things, had this thingy in it:

     PMDIR=$HOME/Procmail
     INCLUDERC=$PMDIR/list.rc

list.rc is where I had the recipe kept.

Debugging also helps (in .procmailrc):

            VERBOSE=yes
            LOGABSTRACT=all

# Troubleshooting.

What's really hard to do for this script is find out what went wrong, if anything, since you don't get immediate feedback. Your Error Logs are GREAT places to start looking. Also, it's a really good idea to test your script on a command line. If you have telnet access you can type in:

            perl -c mojo_send.pl

which will tell perl to compile -but not run the script, and report back any errors. Very handy.

You can also use the script right on the command line, just write out a mail message with the mail headers and your body, your headers and body should be seperated by two lines:

            To: newsletter@skazat_design.com
            From: justin@skazat.com
            Subject: This
            is a test from the command line in telnet

            Hello, is anyone there? I should receive this, as should everyone
            else on my list!

Type Control-D when your done writing to tell Perl that you are done.

To test the script, add the '--test' flag when you execute the script:

     perl mojo_send.pl --test

And then write your message. The message will now only be sent to the list owner.

Another great idea is to change the $MAIL_SETTINGS variable, located in the Config.pm file, to a file name, like this:

            $MAIL_SETTINGS = '>>/usr/home/path/to/testfile.txt';

the '>>' tells Mojo to append every mail message to the end of the file, instead of writting over it. Changing the $mail_setttings to a filename will make every e-mail you 'send' be appended to this file, instead of being actually e-mailed out. Running the script on the command line and changing the $MAIL_SETTINGS to a file takes the entire mail program out of the system, so you can see if its the mail program giving you trouble, or something else.

# How The Script Works

This script receives your e-mail message and parses the headers - the part of the e-mail you usually don't see - that contain information about who the e-mails from and where it's to. If the E-mails From: is the same as the name of the special email alias address you just setup (essentially, the To: is the same as the From:), it'll stop cold and write an error to your log. This usually means that the script is trying to send a message to iteself, and it will do so, for a very long time, unless we stop it right away.

After that, the script sees if there's a list short name that matches what you named the special e-mail address. If nothing matches. It stops. mojo_send.pl should write something in your error log that says it couldn't find the list. It also sends an e-mail to the person trying to send to the unknown list telling them there isn't a list by that name.

If it finds the list, it opens up that list's information and sees if the e-mail from either the list owner or list administrator if its an announce-only list, or, if its from anyone that's subscribed to the list if your list is a group list. If it isn't from the right people it will e-mail back to the person telling them they aren't allowed to send email messages to the list. You can edit what this message looks like in your list's control panel under ``Customize E-mail Messages''.

If the right person is sending to the e-mail list, the message gets sent. E-mails will be formatted as you specify in the ``Customize E-mail Messages'' section in your list's Control Panel. mojo_send.pl will also archive your message just like it does when you send messages from your control panel.

# A Word of Caution

mojo_send.pl may not be the most secure script to use, some nasty person can fake e-mail headers, and send to a list its not supposed to. Sending e-mails from your list's Control Panel is much more secure, though you lack the Group E-mail feature. You can't change or retreive any of your list's information using mojo_send.pl, which is good. Be aware that there's reasons why programs such as Majordomo are so hard to setup - they're also much more secure when sending e-mails to scripts this way.

# Special Commands Sent to mojo_send.pl

mojo_send.pl doesn't support any special e-mail commands, such as subscribe, unsubscribe or information about the list. We find the web-based way of getting this information is alot easier to use. This also makes mojo_send.pl much simpler and certainly easy to customize if you know perl well enough. You can add these features to a similar script, perhaps set up an email address called mojo@yourdomain.com and a script that reads information sent from that address. The script could take care of subscribe/unsubscribe requests by email. Just a thought!

# COPYRIGHT

Copyright (c) 1999 - 2002 Justin Simoni (justin@skazat.com) http://justinsimoni.com All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.