Apache James 简称 James, 是 Java Apache Mail Enterprise Server的缩写。James 是100%基于Java的电子邮件服务器。它是一种独立的邮件服务器,并提供了一个完整的电子邮件解决方案,用来收、发电子邮件。
由于要研究SOA下,用邮件交换信息。所以研究Apache James。
本文操作的系统环境:
1. JDK 1.5.22
2. JMail API v1.4.2
3. Apache James 2.3.1
4. Windows 2000 Server sp4
1。请下载安装JDK,并设置好其环境变量:JAVA_HOME=……
3。Apache James 的官方网站为:http://james.apache.org/,当前 Server 的最新版为 2.3.2版. 安装非常简单,下载后得到james-binary-2.3.2.zip 文件,解压后即可。这里假设解压到D盘(D:/lug_learn/james-2.3.2),目录结构如下:
D:/lug_learn/james-2.3.2
|--- apps
|--- bin
|
…………
4。启动 James 服务器
双击或在命令行下执行D:/james-2.3.1/bin 目录下的 run.bat文件,即可启动 James 服务器。
启动后能在控制台看到如下信息,说明启动成功:
Using PHOENIX_HOME: D:/lug_learn/james-2.3.2
Using PHOENIX_TMPDIR: D:/lug_learn/james-2.3.2/temp
Using JAVA_HOME: C:/Program Files/Java/jdk1.5.0_22
Phoenix 4.2
James Mail Server 2.3.2
Remote Manager Service started plain:4555
POP3 Service started plain:110
SMTP Service started plain:25
NNTP Service started plain:119
FetchMail Disabled
要关闭 James 服务,请使用 Ctrl + C
说明:启动前请确保您的JDK环境变量如JAVA_HOME等已经设置好;James 启动时,其SMTP 服务默认在 25 端口启动,POP3 服务默认在 110 端口启动, NNTP 服务默认在 119 端口启动, 请确保这些端口未被占用。比如本系统下就已经安装了Microsoft的 SMTP 服务,造成 James无法启动,解决方法为:开始--->设置--->控制面板--->管理工具--->服务,打开后找到“Simple Mail Transport Protocol(SMTP)”服务项,关闭即可。
5。配置服务
打开D:/lug_learn/james-2.3.2/apps/james/SAR-INF 下的 config.xml 文件,初次启动James之前,不会有这个文件,只有当James服务启动一次之后才自动构件该文件。
找到
- ……
- <postmaster>Postmaster@localhost</postmaster>
- ……
- <servernames autodetect="true" autodetectIP="true">
- <servername>localhost</servername>
- </servernames>
- ……
……
<postmaster>Postmaster@localhost</postmaster>
……
<servernames autodetect="true" autodetectIP="true">
<servername>localhost</servername>
</servernames>
……
把localhost该成你自己想要的机器名或者域名, 把自动探测IP属性设置为“false”
<postmaster>lug@lug2</postmaster>
……
<servernames autodetect="true" autodetectIP="true">
<servername>lug2</servername>
</servernames>
…… <postmaster>Postmaster@zhaipuhong.com</postmaster> …… <servernames autodetect="false" autodetectIP="false"> <servername>zhaipuhong.com</servername> </servernames> ……
找到
- <mailet match="RemoteAddrNotInNetwork=127.0.0.1" class="ToProcessor">
- <processor> relay-denied </processor>
- <notice>550 - Requested action not taken: relaying denied</notice>
- </mailet>
<mailet match="RemoteAddrNotInNetwork=127.0.0.1" class="ToProcessor"> <processor> relay-denied </processor> <notice>550 - Requested action not taken: relaying denied</notice> </mailet>
将其注释,结果如下:
- <!--mailet match="RemoteAddrNotInNetwork=127.0.0.1" class="ToProcessor">
- <processor> relay-denied </processor>
- <notice>550 - Requested action not taken: relaying denied</notice>
- </mailet-->
<!--mailet match="RemoteAddrNotInNetwork=127.0.0.1" class="ToProcessor"> <processor> relay-denied </processor> <notice>550 - Requested action not taken: relaying denied</notice> </mailet-->
找到下面元素,去掉其注释
- <authRequired>true</authRequired>
<authRequired>true</authRequired>
这样邮箱访问需要帐号验证。
如此,James服务配置已经完成。
6。创建邮件帐号
创建邮件帐号后,就可以用来收发邮件了。James的账号管理是通过基于Telnet客户机的远程管理器,这点颇为不爽,尤其是我的操作系统下的命令行控制台是不显示telnet命令输入字符的,经常出错。
现在进入命令行控制台,在telnet localhsot 4555 进入James管理器,操作如下:
C:/Documents and Settings/db2admin>telnet localhost 4555
C:/Documents and Settings/db2admin>telnet localhost 4555
将进入
JAMES Remote Administration Tool 2.3.1 Please enter your login and password Login id:
默认的登陆id 为root 密码也为 root ,登陆成功后结果如下:
JAMES Remote Administration Tool 2.3.2
Please enter your login and password Login id: Password: Welcome root. HELP for a list of commands
创建新用户的命令是:adduser username password
这里创建了两个账户来作为演示使用: lug/lug ; lug2/ lug2
说明:你可以输入help来获取命令帮助
help display this help 显示帮助信息 listusers display existing accounts 显示现有账户 countusers display the number of existing accounts 显示现有账户数量 adduser [username] [password] add a new user 添加一个新用户 verify [username] verify if specified user exist 核实指定用户是否存在 deluser [username] delete existing user 删除存在的用户 setpassword [username] [password] sets a user's password 设置用户密码 setalias [user] [alias] locally forwards all email for 'user' to 'alias' 设置邮箱别名 showalias [username] shows a user's current email alias 显示别名 unsetalias [user] unsets an alias for 'user' 删除用户别名 setforwarding [username] [emailaddress] forwards a user's email to another email address 转发用户的电子邮件地址到另一个电子邮件地址 showforwarding [username] shows a user's current email forwarding 显示用户的当前邮件转发 unsetforwarding [username] emoves a forward 删除转发 user [repositoryname] change to another user repository 改变另一个用户库 shutdown kills the current JVM (convenient when James is run as a daemon)关闭当前的服务 quit close connection 关闭连接
完成上面,邮件服务器基本上可以用了。
7 尝试使用mailing list。研究了很长时间。邮件服务器启动都正常,也能够发出。就是无法收到。
参考 http://james.apache.org/server/2.3.2/mailing_lists.html
首先在config.xml文件的<spoolmanager>标签下,有一个<processor name="root">标签,在这个block内的<mailet match="All" class="ToProcessor">前面,添加如下一段:
<mailet match="CommandForListserv=james@lug2"
class="AvalonListservManager">
<repositoryName>list-james</repositoryName>
</mailet>
<mailet match="RecipientIs=james@lug2"
class="AvalonListserv">
<repositoryName>list-james</repositoryName>
<membersonly>false</membersonly>
<attachmentsallowed>true</attachmentsallowed>
<replytolist>true</replytolist>
<autobracket>true</autobracket>
<subjectprefix>JamesList</subjectprefix>
</mailet>
邮件列表mailet需要一个数据仓库来保存订阅者列表。每个邮件列表都有一个单独的数据仓库,并且完全独立于James用来管理e-mail账号的用户数据仓库。这在config.xml文件中的<users-store>配置块中。
<repository name="list-name"
class="org.apache.james.userrepository.UsersFileRepository">
<destination URL="file://var/lists/list-name/" />
</repository>
8 后来考虑使用
LISTSERV
可以到 http://www.lsoft.com/ 下载免费版。免费版只能创建10个list。500个订阅者。