ZenPhoto with Mailman Print

  • 0

Send random recurring articles and photos from ZenPhoto using mailman. Users self register with mailman using the built in web interfaceand their own email. Your administrative work is simply to review subscribers and create content in ZenPhoto.

You will need

  • an SSH account which is an add-on for lower level hosting accounts
  • cron for scheduling
  • ZenPhoto with MySQL and PHP which are standard in our hosting environment
  • Mailman which is available for our higher level accounts

Mailman

Set up your new mailing list configuring as you normally would using Mailman installation instructions

Set these parameters:

  • Hide the sender of a message, replacing it with the list address (Removes From, Sender and Reply-To fields): Yes
  • Should any existing Reply-To: header found in the original message be stripped? Yes
  • Where are replies to list messages directed? Poster is recommended for most mailing lists: Explicit address
  • Explicit Reply-To: <your email address>
  • Maximum length in kilobytes (KB) of a message body. Use 0 for no limit: 1024 (or higher to allow images)

Non-digest options:

  • Footer added to mail sent to regular list members:
    <You name> <frequency> <description> mailing list.
    To subscribe: send an email to <you>@<domain>
    To unsubscribe: send an email to <unsubscribe>@<domain>

Privacy Options:

  • Who can view subscription list? List admin only

Privacy Options > Sender filters:

  • By default, should new list member postings be moderated? Yes

 

Add a new mail account for this mailing list.

Use your password generator to create a unique name because this is the only way you can obscure your mail address for this list. If anyone does decipher your email account name, they could fake the address and spam your whole mailing list.

For this demo setup use account "zenphoto" on server "myserver.domain.com". Email sent from this machine will come from zenphoto@myserver.domain.com. Add this new email account as a member in mailman. Uncheck the moderation flag for this account only so only this account will be able to broadcast to the mailing list. All other accounts should normally have the moderation flag checked to control sending to the full list.

Set up the mail script.

Add a new directory outside your web site path and add the script file: zenphoto-mail.sh with this code:

#!/bin/bash

# note: this script needs one dry run to generate all the needed files

### CONFIG ##########################
SUBJECT="Photo from Me"
FROM="your_actual_email@yourphotosite.com"
MAIL_TO="weekly@lists.yourphotosite.com"
#####################################
IMG_DIR="/home/photo123/yourphotosite.com/albums"; # no trailing slash
FILE_LIST="/home/photo123/yourphotosite.com/lists/weekly.files"
LOG="/home/photo123/yourphotosite.com/lists/weekly.log"
TMP="/home/photo123/yourphotosite.com/lists/weekly.tmp"
MESSAGE="/home/photo123/yourphotosite.com/lists/weekly.msg"
## MESSAGE BODY #####################
echo "Here's your totally random weekly Photo from Me :-)" > $MESSAGE
echo "" >> $MESSAGE
#echo "You may find deeper meaning in this, but only if you really want to." >> $MESSAGE
#echo "You may even find the answer to a question you've pondered for many days, or even years!" >> 
$MESSAGE
#echo "Then again, you may want to consult your coffee grinds on that one." >> $MESSAGE
#echo "" >> $MESSAGE
#echo "Cheers!" >> $MESSAGE
#echo "" >> $MESSAGE
## DB ###############################
DB_HOST="localhost"
DB_NAME="<your db name>"
DB_USER="<your db user>"
DB_PASS="<your db password>"
### END CONFIG #####################

# Find all the candidate images, and log them to a temporary list file
find $IMG_DIR -iregex ".*.jpg" > $FILE_LIST

# Select a random file from the list
LowerBound=1
RandomMax=32767
UpperBound=$(cat $FILE_LIST | wc -l)

# Check the log and see if we already sent this picture, and if we did, select
# a new one. If after 30 random attempts, there are no new pictures, just send it.
UNIQUE=0
COUNTER=0
until [ $UNIQUE -gt 0 ]; do 
RandomLine=$(( $LowerBound + ($UpperBound * $RANDOM) / ($RandomMax + 1) ))

# Use sed to grab the random line
FILE=$(sed -n "$RandomLine{p;q;}" "$FILE_LIST")
BASE_FILE=`basename "$FILE"`

if ( grep "$BASE_FILE" $LOG ); then
UNIQUE=0
else
UNIQUE=1
fi
let COUNTER=COUNTER+1
if [ $COUNTER -gt 30 ]; then
UNIQUE=1
fi
done

echo $(date) :: "$FILE" >> $LOG

# Select the image title
IMG_TITLE=`
mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASS << EOF
use $DB_NAME;
SELECT title
FROM zp_images
WHERE filename = '$BASE_FILE'
LIMIT 1;
EOF`
IMG_TITLE=${IMG_TITLE:6}
echo $IMG_TITLE > $TMP
IMG_TITLE=`sed -r "s/\&amp\;/\&/g" $TMP`

# Select the image description
IMG_DESC=`
mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASS << EOF
use $DB_NAME;
SELECT zp_images.desc
FROM zp_images
WHERE filename = '$BASE_FILE'
AND zp_images.desc != 'NULL'
LIMIT 1;
EOF`
IMG_DESC=${IMG_DESC:5}
echo $IMG_DESC > $TMP

IMG_DESC=`sed -r "s/\&amp\;/\&/g" $TMP`
echo $IMG_DESC > $TMP

IMG_DESC=`sed -r "s/\\n//g" $TMP`
echo $IMG_DESC > $TMP

IMG_DESC=`cat $TMP`

echo $IMG_TITLE >> $MESSAGE
echo $IMG_DESC >> $MESSAGE

cat $MESSAGE

mutt -s "$SUBJECT :: $IMG_TITLE" -a "$FILE" $MAIL_TO < $MESSAGE

Change all of the settings under CONFIG to match your setup and make sure you save the file somewhere no one can access through the web.

Run the file (./weekly-mail.sh), and it will generate all of the necessary files for logging and keeping track of already sent pictures, to prevent duplicates.

 

Use cron to call our script.

Now we need to run the script once a week. To do that, simply add the following to your cron configuration. It can be called through "crontab -e", or your web host may have a web interface.

MAILTO="yourname@yoursite.com"
# m h dom mon dow   command
0 0 * * 6       /home/photo123/scripts/weekly-mail.sh

First line specifies the email to send cron error/log information.

The third line runs the script. Change the path to point it to your script

 


Was this answer helpful?

« Back

Powered by WHMCompleteSolution