开始之前,先声明一下本文操作的系统环境:
1. JDK 6u10b
2. JMail API v1.4.2
3. JAF API v1.1(JavaBean Activation Framework)
4. Apache James 2.3.1
5. Eclipse 3.4 for J2EE Developers
6. Windows 2000 Server sp4
3。Apache James 的官方网站为:http://james.apache.org/,当前 Server 的最新版为 2.3.1版. 安装非常简单,下载后得到james-binary-2.3.1.zip 文件,解压后即可。这里假设解压到D盘(D:\james-2.3.1),目录结构如下:
D:\james-2.3.1
|--- apps
|--- bin
|
…………
4。启动 James 服务器
双击或在命令行下执行D:\james-2.3.1\bin 目录下的 run.bat文件,即可启动 James 服务器。
启动后能在控制台看到如下信息,说明启动成功:
Java代码
Using PHOENIX_HOME: D:\james-2.3.1
Using PHOENIX_TMPDIR: D:\james-2.3.1\temp
Using JAVA_HOME: D:\Java\jdk1.6.0_10
Phoenix 4.2
James Mail Server 2.3.1
Remote Manager Service started plain:4555
POP3 Service started plain:110
SMTP Service started plain:25
NNTP Service started plain:119
FetchMail Disabled
Using PHOENIX_HOME: D:\james-2.3.1
Using PHOENIX_TMPDIR: D:\james-2.3.1\temp
Using JAVA_HOME: D:\Java\jdk1.6.0_10
Phoenix 4.2
James Mail Server 2.3.1
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)”服务项,关闭即可。
现在进入命令行控制台,在telnet localhsot 4555 进入James管理器,操作如下:
C代码
C:\Documents and Settings\db2admin>telnet localhost 4555
C:\Documents and Settings\db2admin>telnet localhost 4555
将进入
C代码
JAMES Remote Administration Tool 2.3.1 Please enter your login and password Login id:
JAMES Remote Administration Tool 2.3.1 Please enter your login and password Login id:
默认的登陆id 为root 密码也为 root ,登陆成功后结果如下:
C代码
JAMES Remote Administration Tool 2.3.1
Please enter your login and password
Login id:
Password:
Welcome root. HELP for a list of commands
JAMES Remote Administration Tool 2.3.1
Please enter your login and password
Login id:
Password:
Welcome root. HELP for a list of commands
创建新用户的命令是:adduser username password
这里创建了两个账户来作为演示使用: zhaipuhong/zhangpuhong ; zph/zph
说明:你可以输入help来获取命令帮助
C代码
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 关闭连接
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 关闭连接
说明: 执行测试时,先执行发送,在main方法中注释掉邮件接受方法调用,等待片刻,再注释掉邮件发送方法调用,执行邮件接受方法调用。因为就算163这样优秀的企业级邮箱也不可能瞬间就能收到发送的邮件。
在邮件发送方法中:sendMail(), 可以尝试一下又本邮件服务器向163邮箱发送邮件,如果想通过163邮件服务器想本地发送邮件,你需要配置DSN。
以下为本机接收James邮件服务器提供服务的邮件结果:
0: zhaipuhong@zhaipuhong.com I hava my own mail server Return-Path: <zhaipuhong@zhaipuhong.com> Delivered-To: zph@zhaipuhong.com Received: from 127.0.0.1 ([127.0.0.1]) by ZPH (JAMES SMTP Server 2.3.1) with SMTP ID 693 for <zph@zhaipuhong.com>; Wed, 9 Jul 2008 19:58:38 +0800 (CST) Date: Wed, 9 Jul 2008 19:58:38 +0800 (CST) From: zhaipuhong@zhaipuhong.com To: zph@zhaipuhong.com Message-ID: <11627000.01215604718796.JavaMail.db2admin@ZPH> Subject: I hava my own mail server MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From now, you have your own mail server, congratulation! 0: zhaipuhong@zhaipuhong.comI hava my own mail server
Return-Path: <zhaipuhong@zhaipuhong.com>
Delivered-To: zph@zhaipuhong.com
Received: from 127.0.0.1 ([127.0.0.1])
by ZPH (JAMES SMTP Server 2.3.1) with SMTP ID 693
for <zph@zhaipuhong.com>;
Wed, 9 Jul 2008 19:58:38 +0800 (CST)
Date: Wed, 9 Jul 2008 19:58:38 +0800 (CST)
From: zhaipuhong@zhaipuhong.com
To: zph@zhaipuhong.com
Message-ID: <11627000.01215604718796.JavaMail.db2admin@ZPH>
Subject: I hava my own mail server
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From now, you have your own mail server, congratulation!