2010/09/28

PHPLIST 使用及設定 - 發信設定

phplist 是一套功能很強大的發信工具,但他的製報功能不是很強.....
http://www.phplist.com/

這是他的特色(官方網站說明)
  • phplist is a one-way email announcement delivery system. It is great for newsletters, publicity lists, notifications, and many other uses. (It is different from group mailing list systems like mailman.)
  • The Web Interface lets you write and send messages, and manage phplist over the internet.
  • phplist keeps sending messages from your web server, even after you shut down your computer.
  • 100 000 + subscribers. phplist is designed to manage mailing lists with hundreds of thousands of subscribers. phplist is excellent with smaller lists too!
  • No duplicate messages. No 'forgotten' messages. phplist manages message delivery with a message queue, ensuring that every subscriber gets the email message, and that no subscribers receive two copies, even if they're subscribed to more than one list!
  • Open/View Tracking tells you how many users opened your email message. This provides a minimum statistic, as many email clients with privacy or security policies block images (gmail, thunderbird, and others).
  • Click Tracking tracks links and URLs. Statistics can be viewed by message, URL or subscriber.
  • Multiple Subscribe Pages allow you to choose many different combinations of templates, languages, user attributes and lists.
  • Templates are completely customizable, and make site integration a breeze.
  • Multiple Templates on different subscribe pages can integrate phplist with several different web sites.
  • Subscriber Attributes like 'name', 'country', and other personal information, are completely customizable. You can specify what information you need to get from users when they subscribe.
  • User Specific Content. You can use Subscriber Attributes in message content to make each and every email message personalized with the subscribers name, country, or any other attribute.
  • HTML email messages. Subscribers can be given the choice between text or html email messages. You decide whether subscribers can choose, what the default choice is, and what format a message is sent in: text only, html only, or both!
  • The HTML Editor allows you to edit html messages from phplist using FCKeditor. TinyMCE is also available.
  • Internationalization. phplist is available in English, French, German, Spanish, Portuguese, Traditional Chinese, Dutch, Vietname and Japanese and translation work is in progress for other languages.
  • Easy Install via Fantastico, FTP upload, or SSH.
  • Multiple List Administrators. The super-admin can assign lists to List Managers, who can manage their users and lists. The super-admin user can 'prepare' messages that can be sent by list managers to their lists.
  • Subscriber Preferences. Every email message contains personalized URLs for subscribers to update their preferences or unsubscribe. Subscribers can update their own information and keep your database up to date. Unlike most other mailing list managers, in phplist subscribers can change their email address.
  • The User Management tools are excellent to manage and maintain large databases of subscribers.
  • Bounce Processing keeps your database clean of unused and non-existent email addresses.
  • Advanced Bounce handling let's you teach phplist to distinguish between permanent and temporary message-delivery errors. You can define automated actions on receipt of bounce messages according to matches with your regular expressions.
  • CSV Import and Export. Use CSV and tab delimited files to import your existing list of users or to export the users on the phplist system for use in your in-house database. phplist's database has a 'foreign key' to help keep multiple copies of databases synchronized without duplicating users.
  • Attachments can be uploaded and included in messages for download.
  • Send a Web page. Tell phplist the URL of a web page you want to send to your users, and phplist will fetch it and send it. You can even put subscriber-specific parameters in the URL.
  • RSS feeds can be automatically sent to a mailing list weekly, daily, or monthly.
  • PDF messages can be automatically created and sent as attachments to ensure that your message is seen the way it was designed by all your subscribers, regardless of their email message reader.
  • Batch Processing is useful in shared hosting environments. Set the maximum number of sent messages in a given time period.
  • Throttling can limit the load on your server so it doesn't overload.
  • Domain Throttling limits the number of emails to specific domains to keep on the friendly side of their system administrators.
  • Scheduled Sending let's you tell phplist when the message is to be sent.
  • Repetition. A message can be repeated automatically to send updated dynamic content and attachments.
  • Text from HTML. Text email messages are managed fluently in phplist. phplist will automatically create a text version of an html message. Optionally the message composer can create it manually.
  • PGP signing and encrypting (soon).
    Send your message digitally signed or encrypted, or both.
  • Email to Fax (soon).
    Configure the details of your favourite email 2 fax gateway and phplist will send the HTML version of the message as a PDF attachment to your fax gateway. The fax will include the images in the HTML.
  • Integration with other tools. Several systems exist on the internet that integrate phplist with your favourite CMS or blogging tool. Check out the Documentation for a list.

連台大的的電子發報平台都是用它改寫的
http://epaper.ntu.edu.tw/


他的安裝請參考官方網站的說明,中文有空我在來寫
http://docs.phplist.com/PhplistInstallation

我要備註的是這一段,關於 README.commandline 的設定方式
官方的文件是這樣寫的
Running PHPlist from the commandline

Commandline processing requires PHP 4.3.0 or higher

A few pages in the PHPlist system can now, as of version 2.7.0 be run with
a simple command from the commandline.

the script to use is called "phplist" in the "bin" directory. You will have to edit
this script to fit your system

The normal PHPlist access restrictions are bypassed, but the Unix users who are
allowed to run the script should be mentioned in the "commandline_users" config
variable. The identity of a user is determined by the USER environment variable, which
may not always match your system.

The "p" parameter is the page that needs to be run.
Currently you can use "send", "processqueue" and "processbounces"

phplist -psend

This will require some more arguments:

-l list
-s subject
[-f from]

and you need to "pipe" the message into the script.

The -l parameter can have two types of values, the name of the list or the number of the list.
You can added multiple lists or multiple -l parameters
The subject can have spaces
The from is optional. It will default to the system administrator as set up in your config.

So the full "send" command line would be:

phplist -psend -s This is the subject -l test 1 2 3 -f me@server.com < messagefile




* 於是我在我的命令列下這樣的指令 /bin/phplist -p processqueue (處理電子報queue 的信件),它執行了一段時間,因為我設定發 300 封信後,需要休息 300 秒才可以繼續在工作,免得被當成廣告信件。如果這個動作在網頁上執行,它就會把該網頁綁住,然後一直的用 javascript 跑一個執行寄信的畫面,並且鎖住 browser 避免你關掉。但是如果可以把這一段寫成 cron(排成) 放在系統中讓他自己跑就會方便許多了。
epaper@www:~$ /home/epaper/bin/phplist -p processqueue
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com
Started
Sending in batches of 300 emails
Script stage: 6
Finished, Nothing to do
Finished, All done
epaper@www:~$ /home/epaper/bin/phplist -p processqueue
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com
Started
Sending in batches of 300 emails
Processing has started, 1 message(s) to process.
Processing message 66
Looking for users
Found them: 778 to process
batch limit reached: 300 (300)
Script stage: 5
300 messages sent in 335.89 seconds (3215 msgs/hr)
1 invalid emails
Finished this run
Reload required
You have mail in /var/mail/epaper

* 但是有想到另外一個問題,就是當一個發信的工作跑了很久可能需超過 24 hr 以上的時間發信,系統的處理是等待.....,所以這樣就不會有搶工作佇列的問題。
epaper@www:~$ /home/epaper/bin/phplist -p processqueue
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com
A process for this page is already running and it was still alive 1 seconds ago
Running commandline, quitting. We'll find out what to do in the next run.

* 所以如果第二次發信的時候,phplist 會把剛剛發過得扣除,然後在發一次然後在等待 300 秒才會結束程式。所以看起來如果要自動跑的話寫 5min 跑一次,看起來是可以接受的。
epaper@www:~$ /home/epaper/bin/phplist -p processqueue
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com
Started
Sending in batches of 300 emails
Processing has started, 1 message(s) to process.
Processing message 66
Looking for users
Found them: 477 to process

* 如果你有設定好的話,它應該會發一封信到你的信箱去,告訴你大概做了什事....
To: epaper@epaper.cm.nsysu.edu.tw
Subject: PHPlist Maillist Processing info
Recieved:
From: EpaperWebmaster
X-MessageID: systemmessage
X-ListMember: epaper@epaper.jangmt.com
X-UID: 4790


Started
Sending in batches of 300 emails
Processing has started, 1 message(s) to process.
Processing message 66
Looking for users
Found them: 778 to process
batch limit reached: 300 (300)
Script stage: 5
300 messages sent in 335.89 seconds (3215 msgs/hr)
1 invalid emails


* 但是你知道發信總是有人的 email 會是錯誤的,所以要定時的收取退件清單。這些清單會被收進系統的資料庫內,並且予以紀錄。只要修正這些原始的資料,就可以排除了
epaper@www:~$ /home/epaper/bin/phplist -p processbounces
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com
110 bounces to fetch from the mailbox
Please do not interrupt this process
25 done
50 done
75 done
100 done
Closing mailbox, and purging messages
Identifying consecutive bounces
Identifying consecutive bounces
0 of 355 users processed
Identifying consecutive bounces
10 of 355 users processed
Identifying consecutive bounces

* 於是乎加上了排成,我寫成這樣的方式,使用這 epaper 使用 crontab -e 編輯 crontab ,每 20 min 收一次退信,每 5 min 處理信件佇列。
# m h dom mon dow command
*/5 * * * * /home/epaper/bin/phplist -p processbounces
*/20 * * * * /home/epaper/bin/phplist -p processqueue

* BUT 人生就是因為有那麼多的 but 才顯得有趣,系統會告訴你某個變數沒有定義,不讓你跑....錯誤訊息如下
Error: USER environment variable is not defined, cannot do access check. Please make sure USER is defined.
PHPlist version 2.10.12 (c) 2000-2010 Tincan Ltd, http://www.phplist.com

* 那怎麼辦勒,只好自己手工產生變數了...於是我修改了 cron 並自己改寫了一個 shell script
epaper@www:~$ vim epaper_cron.sh
#!/bin/bash
# 手工把變數輸出,應該只是要 USER 這個變數而已...
SHELL=/bin/bash
USER=epaper
MAIL=/var/mail/epaper
PATH=/home/epaper/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
PWD=/home/epaper
LANG=zh_TW.UTF-8
HOME=/home/epaper
LANGUAGE=zh_TW:zh
LOGNAME=epaper
export SHELL
export USER
export MAIL
export PATH
export PWD
export LANG
export HOME
export LANGUAGE
export LOGNAME
/home/epaper/bin/phplist -p processbounces
/home/epaper/bin/phplist -p processqueue

* 排成改了變成這樣
epaper@www:~$ crontab -e
m h dom mon dow command
*/5 * * * * /home/epaper/epaper_cron.sh >> /home/epaper/epaper_cron.log
* 然後就一切正常了, 可以到 /home/epaper/epaper_cron.log 看系統產生的 log


* 另外系統為了避免你一直 try 錯誤的信箱,於是有個文件 README.bounces 可以設定當遇到多少次退信後就不再嘗試寄信了。
In the admin pages, you can now load the bounces in the PHPlist database. Some bounces are not
always really bounces, but they can be "Message delayed" or "Out of Office" messages. Therefore
PHPlist will not immediately unsubscribe a user when a message has bounces, but it will determine
a treshold of messages which will identify a bounce.

You set the threshold with the variable

$bounce_unsubscribe_treshold = 3;

This variable will be used to returns of normal messages. If "systemmessages" return, a user will
be unsubscribed immediately. Unsubscribed means that their email will be marked unconfirmed, which
will cause the system to stop sending emails to this user.

In the future it will become possible to "probe" the unconfirmed emails with a renewed request for
confirmation, which will be dealt with seperately, most likely by simply deleting the user.

If a message to a user bounces, the threshold will be used to determine the previous number of
message that have bounced. A user will only be marked unconfirmed once a row of consecutive messages
as many as your threshold have occurred.

If you run in TEST mode, the emails in the bounce system will not be deleted from the mailbox. If you
have set TEST to 0, it will delete the emails it has dealt with, according to the settings

$bounce_mailbox_purge = 1;
and
$bounce_mailbox_purge_unprocessed = 1;

$bounce_mailbox_purge can be 1 or 0, and 1 means that messages that have been processed and identified
will be delete from the mailbox. $bounce_mailbox_purge_unprocessed can be 1 or 0 as well, and
1 means that also unprocessed messages, which are messages that could not be matched with a user in
the system, will be deleted. This is fairly safe, because you can still look at the messages
in PHPlist.
.

* 關於 bounces 的處理,需要建立一個帳號,來收取信件處理。設定檔一樣在 config.php 內
=========================================================================

Settings for handling bounces

=========================================================================

*/

# Message envelope. This is the email that system messages come from
# it is useful to make this one where you can process the bounces on
# you will probably get a X-Authentication-Warning in your message
# when using this with sendmail
# NOTE: this is *very* different from the From: line in a message
# to use this feature, uncomment the following line, and change the email address
# to some existing account on your system
# requires PHP version > "4.0.5" and "4.3.1+" without safe_mode
$message_envelope = 'listbounces@epaper.jangmt.com';

# Handling bounces. Check README.bounces for more info
# This can be 'pop' or 'mbox'
$bounce_protocol = 'pop';

# set this to 0, if you set up a cron to download bounces regularly by using the
# commandline option. If this is 0, users cannot run the page from the web
# frontend. Read README.commandline to find out how to set it up on the
# commandline
define ("MANUALLY_PROCESS_BOUNCES",1);

# when the protocol is pop, specify these three
$bounce_mailbox_host = 'epaper.jangmt.com';
$bounce_mailbox_user = 'listbounces';
$bounce_mailbox_password = '1234567890xxxxxx';

# the "port" is the remote port of the connection to retrieve the emails
# the default should be fine but if it doesn't work, you can try the second
# one. To do that, add a # before the first line and take off the one before the
# second line

$bounce_mailbox_port = "110/pop3/notls";
#$bounce_mailbox_port = "110/pop3";

# when the protocol is mbox specify this one
# it needs to be a local file in mbox format, accessible to your webserver user
$bounce_mailbox = '/var/spool/mail/listbounces';

# set this to 0 if you want to keep your messages in the mailbox. this is potentially
# a problem, because bounces will be counted multiple times, so only do this if you are
# testing things.
$bounce_mailbox_purge = 1;

# set this to 0 if you want to keep unprocessed messages in the mailbox. Unprocessed
# messages are messages that could not be matched with a user in the system
# messages are still downloaded into PHPlist, so it is safe to delete them from
# the mailbox and view them in PHPlist
$bounce_mailbox_purge_unprocessed = 1;

# how many bounces in a row need to have occurred for a user to be marked unconfirmed
$bounce_unsubscribe_threshold = 5;

* 關於批次處理信件的設定,在設定檔 epaper@www:~/public_html/lists/config$ vim config.php ,可以避免你發信太快被人一直退信或當成垃圾。
# batch processing
# if you are on a shared host, it will probably be appreciated if you don't send
# out loads of emails in one go. To do this, you can configure batch processing.
# Please note, the following two values can be overridden by your ISP by using
# a server wide configuration. So if you notice these values to be different
# in reality, that may be the case

# define the amount of emails you want to send per period. If 0, batch processing
# is disabled and messages are sent out as fast as possible
# define("MAILQUEUE_BATCH_SIZE",0);
define("MAILQUEUE_BATCH_SIZE",300);

# define the length of one batch processing period, in seconds (3600 is an hour)
# define("MAILQUEUE_BATCH_PERIOD",3600);
define("MAILQUEUE_BATCH_PERIOD",300);
張貼留言