首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

邮件服务器

技术前沿 | Exchange | Domino | Sendmail | Postfix | Qmail | IMail | MDaemon | Foxmail | James | Kerio | JavaMail | WinMail | Winwebmail | Merak | CMailServer | 金笛 | 其它 | 邮件与开发 |
首页 > 邮件服务器 > Postfix > Mailing List (邮件列表)原理简述及我的perl实现 > 正文
金笛邮件系统

Mailing List (邮件列表)原理简述及我的perl实现

出处:www.hzqbbc.com 作者:hzqbbc 时间:2006-9-25 11:07:00
简单三步解决企业垃圾邮件难题

注: 本文本来是一早要写的,可是程序写了有段时间了,最近一段时间又很忙,居然给忘了,现在补上。

正文

大部分IT人员都使用过邮件列表,或者类似的服务,但邮件列表的内部工作原理则不是简单的订阅,退订阅那么简单。最近根据自己的一些认识,用perl实现了一个非常简单的MLM程序,也顺便谈谈邮件列表的最基本工作原理。

邮件列表,简单的来说,就是任一列表成员向该列表发的邮件,其他所有人(可以包括他自己)都能收到,并且每个人能自由订阅、退订。更丰富的邮件列表还包括了摘要,精确权限管理,web archive功能等等。

著名的开源邮件列表软件如mailman, majodomo, ezmlm, sympa, ecartis等都是功能完备的邮件列表软件,但归根结底,最简单的邮件列表至少应该包含如下功能:

  • 订阅功能,即用户发特定订阅信件到邮件列表
  • 确认订阅功能,即用户必须给MLM发确认信才能正式订阅
  • 退订功能,用户可自由退出订阅服务。
  • 任一列表成员给邮件列表发的邮件,其他人都应收到。

要实现上述的功能,如果使用perl的话并不复杂,配合Postfix MTA可以非常方便的开发出简易的邮件列表软件。以下是自己开发的MMList(Mini Mailing List) 的基本结构:

MMList atomy(流程图)

配置

基于Postfix,使用alias的方法,将邮件通过管道送到MMList:

main.cf里需要配置的内容:

alias_maps = hash:/etc/postfix/aliases hash:/etc/postfix/mml.aliasesvirtual_alias_maps = hash:/etc/postfix/mml.virtual_alias_maps

mml.aliases的内容:

# alias filetest-subscribe-hzqbbc.com:   "|/usr/bin/mml -cmd=subscribe -list=test@hzqbbc.com"test-confirm-hzqbbc.com:     "|/usr/bin/mml -cmd=confirm -list=test@hzqbbc.com"test-unsubscribe-hzqbbc.com: "|/usr/bin/mml -cmd=unsubscribe -list=test@hzqbbc.com"

mml.virtual_alias_maps的内容:

test-subscribe@hzqbbc.com        test-subscribe-hzqbbc.comtest-confirm@hzqbbc.com          test-confirm-hzqbbc.comtest-unsubscribe@hzqbbc.com      test-unsubscribe-hzqbbc.com

MMList 的perl实现

#!/usr/bin/perl -w# vim: set cindent expandtab ts=4 sw=4:# MMList - a very lightweight MLM software## Author: He zhiqiang <hzqbbc@hzqbbc.com># CopyRight (c) 1998-2005 hzqbbc.com## License: GPL v2use strict;use Getopt::Long;use vars qw(%cfg $cmd $list @KEY_MAP);use vars qw($user $subj $SLOG);$user = $subj = "";@KEY_MAP = (    0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E',    'F','G','H','I','J','K','L','M','N','O',    'P','Q','R','S','T','U','V','W','X','Y',    'Z','a','b','c','d','e','f','g','h','i',    'j','k','l','m','n','o','p','q','r','s',    't','u','v','w','x','y','z');# proto-type:# cmd ==> indicate the 'subscribe' or 'unsubscribe'# list ==> indicate the list namemy $res = GetOptions(	"cmd=s" => \$cmd,        "list=s" => \$list);$cfg{'basedir'} = "/var/lib/mmlist";$cfg{'listdir'} = $cfg{'basedir'}."/lists";$cfg{'hostname'} = "list.hzqbbc.com";open (MLOG, ">> $cfg{'basedir'}/mail.log");open ($SLOG, ">> $cfg{'basedir'}/base.log");# read from STDINwhile(<STDIN>) {     print MLOG $_;      if(/^From: (.*)$/) {          chomp;          m/([a-zA-Z0-9-_=\.]+\@[a-zA-Z0-9-_=\.]+)/;          if($1) {               $user = lc $1;           }      }elsif(/^Subject: (.*)$/) {          chomp;          $subj = $1;          $subj =~ s/\s//g;      }}syslog("cmd = $cmd");if($cmd eq "subscribe") {     if(user_exist($user)) {          syslog("$user subscribed");          my $body = q(Hey guy, you have already subscribed!);          sendmail($user, "Subscribe failure", $body);      }else {          my $sid = gen_sid();          open(FD, "> $cfg{'listdir'}/$list/queue/$user") or              syslog("$!") and die "Can't write to $user, $!\n";          printf FD "%s\:%s\n", time, $sid;          close FD;            syslog("confirm $user");          my $body = "Hey guy, reply to me with the code $sid \n"                    ."in the subject section\n";          $list =~ m/([^:]+)\@(.*)/;          my $from = "$1-confirm\@$2";          sendmail($user, "Confirm subscribe", $body, $from);      }}elsif($cmd eq "confirm") {     if(not user_exist($user)) {          syslog("$user not exist");          if(valid_sid($user, $subj)) {               syslog("added $user");               add_user($user);               my $body = "Welcome to $list :-)\n";               sendmail($user, "Added to the list", $body);           }else {               syslog("fail to confirm $user");               my $body = "Hey guy, your confirm fail, please try again\n";               sendmail($user, "Confirm failure", $body);           }      }else {          my $body = "Hey guy, you step into a wrong situation!\n";          sendmail($user, "Wrong action", $body);      }}elsif($cmd eq "unsubscribe") {     if(user_exist($user)) {          syslog("$user removed");          del_user($user);          my $body = "Hey guy, you have been removed from the $list\n";          sendmail($user, "Goodbye - from $list", $body);      }else {          my $body = "Hey guy, you step into a wrong situation!\n";          sendmail($user, "Wrong action", $body);      }}else {     print STDERR "m3 error cmd!\n";     exit(13);}exit(0);## funcs to handle mail listsub sendmail {     my($to, $subj, $body, $from) = @_;     if(not defined $from) {          $from = "m3\@$cfg{'hostname'}";      }      open(CMD, "| /usr/sbin/sendmail -oi -t -f \"$from\" $to") or          die "Can't exec /usr/sbin/sendmail, $!\n";     print CMD <<EOF Return-Path: $from From: $from To: $to Subject: $subj  $body EOF ;     close CMD;}sub user_exist {     my $user = shift;     if (! -r "$cfg{'listdir'}/$list/users.txt") {          return 0;      }      open(FD, "< $cfg{'listdir'}/$list/users.txt") or die "Can't open $list, $!\n";     while(<FD>) {          chomp;          if(/^$user$/i) {               return 1;           }      }     close FD;     0;}# gen_sid - to generate unique Session idsub gen_sid {     my ($sid, $len) = ("", $_[0] ? $_[0]-1 : 23);     srand(time());     foreach(0...$len) {          $sid .= $KEY_MAP[int rand(61)]; # total of $#KEY_MAP -1      }     $sid;}sub valid_sid {     my ($user, $sid) = @_;     open(FD, "< $cfg{'listdir'}/$list/queue/$user") or         syslog("can't open $user, $!") and die "Can't open $user, $!\n";     $_ = <FD>;     chomp;     ($_) = m/[^:]+:(.*)/;     if($sid eq $_) {          syslog("auth ok for $user");          return 1;      }     close FD;     return 0;}sub add_user {     my ($user) = @_;     unlink "$cfg{'listdir'}/$list/queue/$user"; # clean up user cookie/queue     open(FD, ">> $cfg{'listdir'}/$list/users.txt") or         die "Can't append to users.txt for $list, $!\n";     print FD $user, "\n";     close FD;}sub del_user {     my ($user) = @_;     my $buf = undef;      open(FD, "< $cfg{'listdir'}/$list/users.txt") or         die "Can't open users.txt for $list, $!\n";     while(<FD>) {          chomp;          if(!/^$user$/) {               $buf.="$_\n";           }      }     close FD;      open(FD, "> $cfg{'listdir'}/$list/users.txt") or         die "Can't write to users.txt for $list, $!\n";     print FD $buf;     close FD;}sub syslog {     my ($msg) = @_;     chomp $msg;     printf $SLOG "%s $msg\n", time;}
相关文章 热门文章
  • MarkMail将邮件列表存档推向新境界
  • MDaemon使用技巧大全--邮件列表功能
  • ORF 反垃圾邮件系统-- 导入 Greylisting IP Exception List
  • access-list中in 和out的含义
  • kerio邮件列表如何订阅和推定
  • Greylist的安装[Postfix+FC4]
  • 邮件列表数量越大,电子邮件回应率越低
  • 微软胜诉电子邮件列表销售机构
  • 在FreeBSD上使用minimalist组建邮件列表
  • 使用Forward功能建立邮件列表的方法
  • 用ASP.NET设计高效邮件列表
  • 基于FreeBSD和Postfix的邮件系统与邮件列表的web mail安装4.51
  • Install and configure Postfix with Cyrus-SASL+Cyrus-IMAP+MySQL
  • 在FreeBSD上建立一个功能完整的邮件服务器
  • postfix 邮件病毒过滤
  • 在Fedora上建立自己的邮件服务器
  • Postfix + SpamAssassin 安裝手冊
  • Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP完全指南(新版)
  • Postfix + Cyrus-SASL + Cyrus-IMAPD + PgSQL HOWTO
  • 在FreeBSD5.1簡單安裝Postfix+Qpopper+Openwebmail
  • 在RHEL 4 上配置全功能的Postfix 服务器
  • Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完全指南
  • 我的POSTFIX安装笔记
  • Postfix电子邮局的配置步骤
  • 自由广告区
     
     
    WINMAIL 让您轻松架设邮件系统
    eqmail
    最新软件下载
  • ORF Enterprise Edition 4.2 正式版
  • Exchange Server 2003 群集安装配置
  • ORF 4.2 Beta
  • Exchange 2000/2003 日志分析系统
  • Microsoft Outlook Personal Folders B..
  • MDaemon Server 9.07 英文正式版
  • Kerio MailServer 6.5.1 6098 Linux版
  • Kerio MailServer 6.5.1 6098 正式版
  • 酷邮(KooMail) V5.0 简体中文版
  • PowerGUI 
  • IMail Server 10
  • Foxmail6.5 Beta2
  • 今日邮件技术文章
  • 恶意软件上半年激增278% 攻击目标直指..
  • 企业可考虑移动Email减少运行成本
  • CommVault Simpana增加了新的电子发现..
  • Cyanlotus青莲科技合作伙伴大会上海召开
  • 电邮附件统一管理终实现
  • Pushmail市场孕育新机遇
  • QQ邮箱使用过程中需注意的九个细节
  • 中山大学测试梭子鱼反垃圾邮件系统报告
  • 专家称反垃圾邮件的过程将是漫长的博弈
  • 东北大学温占考:信用机制现身反垃圾工作
  • 给AOL用户发送垃圾邮件 纽约男子被判..
  • Google开发Gmail、Calendar离线功能 ..
  • 最新专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • 移动电子邮件专题
  • Apache James 专题
  • IMail Server 操作指南
  • ISA Server 2004 使用专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2007 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号