Email alerts


I’m just wondering (this might sound like a stupid question), if you can send a daily alert to another (external) email address if the mailbox has mail?

Also, if you create a discussion list, is it possible to make it read only. For example, people can choose to subscribe to a list, but only the moderator can send messages. In other words, to make it a bit like a news service?

Sorry, I’m just new to all this…

If we can send a man to the moon, why can’t we send them all there?


Certainly possible with crontab and script to check POP3.

Well, DreamHost has an announcement list feature but you can only send messages from the web panel. The discussion list software however would let you set it up so that no one can post but those on a special list.

:cool: Perl / MySQL / HTML+CSS


“Certainly possible with crontab and script to check POP3.”

If I knew what this meant I probably wouldn’t have been asking the question on a beginners forum :slight_smile:

If we can send a man to the moon, why can’t we send them all there?


I don’t think DreamHost has anything already setup to help do what you ask easily.

My idea however involves using your shell access to use a utility called crontab to run a program automatically once a day. Now the program would have to check your mailbox, get a message list, and then send an e-mail. DreamHost already has programs that can send an e-mail (mutt, as well as postfix) but it I don’t know of one that can retrieve a list of messages much less do both, so at the moment it appears you’ll need to install something yourself.

I’m working on a short Perl script you could use to do this.

:cool: Perl / MySQL / HTML+CSS


You’d just want to check for the presence of stuff in ~/Maildir/new/; something like this might work:

grep -h "^From: " $HOME/Maildir/new/* || echo "No new mail" | mutt -s "Mail notification"

If you’re using procmail, there’s a useful tool called “mailstat” which can easily be run by cron; it will give you a summary of how many messages were sent to each folder since the command was last run (it just analyzes a procmail logfile). This is probably overkill for this particular situation (and probably a bit more complicated than the OP wanted), but it works quite well.

Something like:

5 0 * * * /usr/bin/mailstat $HOME/.procmail/log |mutt -s "Mail Stats" >/dev/null

(where $HOME/.procmail/log is the procmail log file and is your email address)

This would only work for users that have shell / ftp access (not for the m1231233 users).

The output looks something like this:

[code] Total Number Folder

396690 52 /dev/null
176522 70 formail -D 8192 ~/.procmail/msgid.cache
13269787 263 /home/william/Maildir/
159610 43 lists:dynagroove/
29687 5 lists:hijacked/
163554 3 lists:mutt/
43860 13 lists:mutt-dev/
1071777 310 lists:nanog/
2166123 524 lists:postfix/
479119 127 lists:uuasc/
40662 12 lists:zsh/
4539 1 misc/


most of that goes way above my head :slight_smile:

but, it may not be useful to me anyway, since I specifically would like to do this for the m1001000 users only, not the ftp users.

If we can send a man to the moon, why can’t we send them all there?


That’s what I figured, and for that I think you would have to use a POP3 client or the like. Here is a Perl script that will report the number of messages and disk space used. If the user is already in the habit of not leaving messages on the server /w POP3 or at least moving to a different folder /w IMAP, then the number reported will be new messages.

Edit the “globals” with the appropiate information and upload it. This is not CGI - do not upload to a web-accessible directory. chmod it to 755 before adding it to your crontab file.
After you have chmodded it, you can run it from the shell by typing ‘~/’ and pressing enter. A message should be sent to you if it doesn’t say anything in shell. Also, when you add it to crontab, crontab will send a message to your shell user if there are any errors.
-------------------------------------[code]#!/usr/local/bin/perl -w

use Net::POP3;


my $recipient = ‘name username@host’; # e-mail address to send to
my $mailbox = ‘mailbox name’; # whatever you call the mailbox
my $hostname = ‘’; # incoming mail server!
my $username = ‘username’; # mailbox username!
my $password = ‘password’; # mailbox password!

my $sendmail = ‘|/usr/sbin/sendmail -t’; # do not edit !
my $pop = Net::POP3->new($hostname, Timeout => 30);

if (defined $pop) {
if (defined $pop->login($username, $password)) {
else {
die(“login for $username failed on $hostname”);
else {
die(“failed to connect to $hostname”);


sub message($$) {
my ($count, $byte_size) = @_;
my $kilobyte_size = sprintf(’%0.1fKB’, $byte_size / 1024);
my $megabyte_size = sprintf(’%0.1fMB’, $byte_size / (1024 * 1024));
for ($count, $megabyte_size, $kilobyte_size) {
1 while s/(\d{3})(\d)(?!:\d)/$1,$2/;
return <<MESSAGE;
To: $recipient
Subject: Daily Mailbox Status - $mailbox

Daily Mailbox Status - $mailbox

There are $count messages.
Disk spaced used: $megabyte_size ($kilobyte_size)


sub send($) {
my $message = shift;
open(MAIL, $sendmail) or die(“unable to open sendmail”);
print MAIL $message;
[/code] :cool: Perl / MySQL / HTML+CSS


cool…thanks that is excellent!!!

Just a couple of questions though. I can follow most of that, the only this is I have no idea what a crontab file is?
If I follow your instructions for changing the permissions, and then type ‘~/’ is that all I need to do? I assume once I run it I don’t need to do anything again?

Secondly, I got an email from DreamHost saying that cron thingys are currently disabled?

And lastly, I’m guessing I need to copy this and create a new file for each user that wants these alerts?

thanks again for all the help!

If we can send a man to the moon, why can’t we send them all there?


Login into shell and type ‘crontab’. What this does is allow you to update a text file that keeps a list of commands to run according to a schedule. ‘cron’ is the name of the program that reads the file to run the commands.

It will simply check the mailbox using POP3 and get how many messages there are and how much disk space they take up, send an e-mail message, and quit. So you would have to run it each time you wanted to check the mailbox.

As written, yes. However it wouldn’t be hard to modify the script to get the login information from the command line or from a file. This script is probably not a good idea if other people are using the mailboxes. Naturally it won’t work if they change their password and the script is not updated or told the new password.

:cool: Perl / MySQL / HTML+CSS


[quote]It will simply check the mailbox using POP3 and get how many messages there are…


And, of course, send a copy of all your email to everyone on the forum…



[quote]And, of course, send a copy of all your email to everyone on the forum…

ROFL. No, really, thats a regexp for putting a comma in numbers… :wink:

:cool: Perl / MySQL / HTML+CSS


so, as I understand it, the script will only run once…so if I want it to run on a daily basis, then I would need to add it to the cron thingy, is that right?

If we can send a man to the moon, why can’t we send them all there?


Sorry to bring this up again, this converation was a while ago. I’ve finally found the time to get around to setting up everyone’s email addresses.

I have to thank Atropos7 for writing this script for me. I’ve tested it, and it seems to work great. It’s almost EXACTLY what I need!!!

BUT, I’m just wondering if there IS a way to only send an email if there’s any new messages, and to ONLY report the number of those messages?

Is this possible? Otherwise I will stick with this, but it will probably mean I have to set it to only run weekly, since I think people would get rather annoyed by getting a daily useless email?

Thanks a heap!

If we can send a man to the moon, why can’t we send them all there?