#编者注 以前的老系统使用的是windows上的hmail服务器,因为界面感官好,配置迅速,则为了上线使用。但度过了3年左右,原始配置hmail的人员离职。而且因为Windows的问题,并不可以和Linux系统上的软件打包。而且,因为近期断电事故致使风险加重。因此,须要搭建简单易用的Mail服务器。html
#Apache James Apache James项目提供了一组丰富的开放源代码的模块和库,由Java编写,互联网邮件通讯建设成为先进的企业邮件服务器相关。java
#下载Jamesmysql
#JAVA_HOME [20161102]因为本人第二次的是使用的是mac系统,安装的JDK8,James找不到JAVA_HOME。须要在James当中添加。 ##JAVA_HOME添加到run.sh - 失败 因为James经过bin/run.sh运行,首先尝试的是在run.sh中添加JAVA_HOME,以下内容是在run.sh头部进行添加sql
# -- zhanpeng for mac config JAVA_HOME-- JAVA_HOME=`/usr/libexec/java_home` echo $JAVA_HOME
运行结果数据库
vfxdeiMac:bin zhanpeng$ ./run.sh /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home ERROR: JAVA_HOME not found in your environment. Please, set the JAVA_HOME variable in your environment to match the location of the Java Virtual Machine you want to use.
确认,实际的James的执行是使用phoenix.sh进行执行 ##JAVA_HOME添加到phoenix.sh 在bin/phoenix.sh添加JAVA_HOMEapache
# -- zhanpeng for mac config JAVA_HOME-- JAVA_HOME=`/usr/libexec/java_home`
运行结果windows
vfxdeiMac:bin zhanpeng$ ./run.sh /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home Using PHOENIX_HOME: /Users/zhanpeng/build/james/james-2.3.2.1 Using PHOENIX_TMPDIR: /Users/zhanpeng/build/james/james-2.3.2.1/temp Using JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home Running Phoenix: Phoenix 4.2 James Mail Server 2.3.2.1 Remote Manager Service started plain:4555
#Component named "pop3server" failed to pass through the Starting stage Mac和Ubuntu系统限制普通用户使用1024如下的端口,使用管理员权限运行,就不会发生问题服务器
sudo ./run.sh
#修改James User配置为JDBC **注意:**以下内容在第一次运行james以后才会出现,James使用的是DBCP链接池,默认配置支持Apache Derby、MySQL、MSSQL、HypersonicSQL,查看conf/sqlResources.xml还支持其余数据库。请自行查看 ##修改repository 修改配置文件james-2.3.2.1/apps/james/SAR-INF/config.xml
,这里咱们须要注意,把文件类型的repository注释掉,替换成数据库repositoryapp
<!-- <repository name="LocalUsers" class="org.apache.james.userrepository.UsersFileRepository"> <destination URL="jdbc:sqlite://D:/users.sqlite"/> </repository> --> <!-- Database backed user repositories --> <!-- --> <!-- Use these configurations to store user info in a database. --> <!-- Note: The <data-source> element must refer to a connection configured --> <!-- in the <database-connections> configuration section. --> <!-- The LocalUsers repository, for storing James' User info. --> <repository name="LocalUsers" class="org.apache.james.userrepository.JamesUsersJdbcRepository" destinationURL="db://maildb/users"> <sqlFile>file://conf/sqlResources.xml</sqlFile> </repository>
##JDBC配置 取消注释,并按照jdbc url的格式配置ide
<!-- JDBC driver .jar libraries for other RDBMS can be placed in ~james/lib/ --> <!-- You can download latest Connector/J from --> <!-- http://dev.mysql.com/downloads/connector/j/3.1.html --> <!-- --> <!-- Example, connecting to a MySQL database called "mail" on localhost--> <!-- --> <!-- The max value is the maximum number of concurrent connections James will --> <!-- open to this database--> <!-- If you see "SQLException: Giving up... no connections available." in your --> <!-- log files or bounced mail you should increase this value --> <data-source name="maildb" class="org.apache.james.util.dbcp.JdbcDataSource"> <driver>com.mysql.jdbc.Driver</driver> <dburl>jdbc:mysql://192.168.1.200/james_user?autoReconnect=true</dburl> <user>username</user> <password>password</password> <max>20</max> </data-source>
##添加JDBC驱动到lib 因为编者连接的MySQL兼容mysql-connector-java-5.1.40.jar
添加mysql-connector-java-5.1.40.jar
到james-2.3.2.1/lib
目录,jdbc驱动程序能够去mvnrepo网站下载。
##输出
vfxdeiMac:bin zhanpeng$ sudo ./run.sh /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home Using PHOENIX_HOME: /Users/zhanpeng/build/james/james-2.3.2.1 Using PHOENIX_TMPDIR: /Users/zhanpeng/build/james/james-2.3.2.1/temp Using JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home Running Phoenix: Phoenix 4.2 James Mail Server 2.3.2.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的用户内容,在数据库当中建立了
DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `username` varchar(64) NOT NULL, `pwdHash` varchar(50) DEFAULT NULL, `pwdAlgorithm` varchar(20) DEFAULT NULL, `useForwarding` smallint(6) DEFAULT NULL, `forwardDestination` varchar(255) DEFAULT NULL, `useAlias` smallint(6) DEFAULT NULL, `alias` varchar(255) DEFAULT NULL, PRIMARY KEY (`username`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
#修改James Inbox配置为JDBC
<!-- The inbox repository is the location for users inboxes --> <!-- Default setting: file based repository - enter path ( use "file:///" for absolute) --> <!-- <inboxRepository> <repository destinationURL="file://var/mail/inboxes/" type="MAIL"/> </inboxRepository> --> <!-- Alternative inbox repository definition for DB use. --> <!-- The format for the destinationURL is "db://<data-source>/<table>" --> <!-- <data-source> is the datasource name set up in the database-connections block, below --> <!-- <table> is the name of the table to store user inboxes in --> <!-- The user name is used as <repositoryName> for this repository config. --> <inboxRepository> <repository destinationURL="db://maildb/inbox/" type="MAIL"/> </inboxRepository> <!-- Alternative inbox repository definition for DB use. --> <!-- Stores message body in file system, rest in database --> <!-- <inboxRepository> <repository destinationURL="dbfile://maildb/inbox/" type="MAIL"/> </inboxRepository> --> <!-- Alternative inbox repository definition for mbox use. --> <!-- This method uses UNIX standard mbox files and is meant for people using mbox files --> <!-- with systems such as mail list archive displayers --> <!-- Note that dot-locking is not currently supported --> <!-- so network (write) accesses may cause mbox corruption --> <!-- the sample mbox URL is an absolute URL; mbox:///var/mail will put the users mbox files in /var/mail/--> <!-- <inboxRepository> <repository destinationURL="mbox:///var/mail/" type="MAIL"/> </inboxRepository> -->
inbox表结构
DROP TABLE IF EXISTS `inbox`; CREATE TABLE `inbox` ( `message_name` varchar(200) NOT NULL, `repository_name` varchar(100) NOT NULL, `message_state` varchar(30) NOT NULL, `error_message` varchar(200) DEFAULT NULL, `sender` varchar(255) DEFAULT NULL, `recipients` text NOT NULL, `remote_host` varchar(255) NOT NULL, `remote_addr` varchar(20) NOT NULL, `message_body` longblob NOT NULL, `message_attributes` longblob, `last_updated` datetime NOT NULL, PRIMARY KEY (`repository_name`,`message_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
#修改James Spool配置为JDBC Spool repository是收到的邮件临时存储的本地位置
<!-- Spool repository configuration --> <!-- The spool repository is the location where incoming mails are temporarily stored --> <!-- before being processed. --> <!-- <spoolrepository destinationURL="file://var/mail/spool/" type="SPOOL"/> --> <!-- Alternative spool repository definition for JDBC use --> <spoolrepository destinationURL="db://maildb/spool/spool" type="SPOOL"/> <!-- Alternative spool repository definition for JDBC use --> <!-- Stores message body in file system, rest in database --> <!-- <spoolrepository destinationURL="dbfile://maildb/spool/spool" type="SPOOL"/> -->
数据库表结构
DROP TABLE IF EXISTS `spool`; CREATE TABLE `spool` ( `message_name` varchar(200) NOT NULL, `repository_name` varchar(100) NOT NULL, `message_state` varchar(30) NOT NULL, `error_message` varchar(200) DEFAULT NULL, `sender` varchar(255) DEFAULT NULL, `recipients` text NOT NULL, `remote_host` varchar(255) NOT NULL, `remote_addr` varchar(20) NOT NULL, `message_body` longblob NOT NULL, `message_attributes` longblob, `last_updated` datetime NOT NULL, PRIMARY KEY (`repository_name`,`message_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
#查看并修改James远程管理的用户名密码 查看配置文件,能够看到以下内容,请修改管理密码
<!-- The RemoteManager server is enabled by default --> <!-- Disabling blocks will stop them from listening, --> <!-- but does not free as many resources as removing them would --> <remotemanager enabled="true"> <port>4555</port> <!-- Uncomment this if you want to bind to a specific inetaddress --> <!-- <bind> </bind> --> <!-- Uncomment this if you want to use TLS (SSL) on this port --> <!-- <useTLS>true</useTLS> --> <handler> <!-- This is the name used by the server to identify itself in the RemoteManager --> <!-- protocol. If autodetect is TRUE, the server will discover its --> <!-- own host name and use that in the protocol. If discovery fails, --> <!-- the value of 'localhost' is used. If autodetect is FALSE, James --> <!-- will use the specified value. --> <helloName autodetect="true">myMailServer</helloName> <administrator_accounts> <!-- CHECKME! --> <!-- Change the default login/password. --> <account login="root" password="!changeme!"/> </administrator_accounts> <connectiontimeout> 60000 </connectiontimeout> <!-- The prompt directive adds a prompt to every output from RemoteManager --> <!-- <prompt>james></prompt> --> </handler> </remotemanager>
#telnet登陆并添加用户
vfxdeiMac:SAR-INF zhanpeng$ telnet localhost 4555 Trying ::1... Connected to localhost. Escape character is '^]'. JAMES Remote Administration Tool 2.3.2.1 Please enter your login and password Login id: root Password: !changeme! Welcome root. HELP for a list of commands help Currently implemented commands: 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] removes 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 adduser wangyinghan 123 User wangyinghan added
#使用thunderbird连接 异常提示
接收:POP3,xxx,未加密 发送:SMTP,xxx,未加密 用户名:xxx
查询James文档,得知须要修改useTLS值为ssl POP3
<pop3server enabled="true"> <!-- port 995 is the well-known/IANA registered port for POP3S ie over SSL/TLS --> <!-- port 110 is the well-known/IANA registered port for Standard POP3 --> <port>110</port> <!-- Uncomment this if you want to bind to a specific inetaddress --> <!-- <bind> </bind> --> <!-- Uncomment this if you want to use TLS (SSL) on this port --> <useTLS>true</useTLS> <handler> <!-- This is the name used by the server to identify itself in the POP3 --> <!-- protocol. If autodetect is TRUE, the server will discover its --> <!-- own host name and use that in the protocol. If discovery fails, --> <!-- the value of 'localhost' is used. If autodetect is FALSE, James --> <!-- will use the specified value. --> <helloName autodetect="true">myMailServer</helloName> <connectiontimeout>120000</connectiontimeout> </handler> </pop3server>
SMTP
<smtpserver enabled="true"> <!-- port 25 is the well-known/IANA registered port for SMTP --> <port>25</port> <!-- Uncomment this if you want to bind to a specific inetaddress --> <!-- Please NOTE: you should add this IP also to your RemoteAddrNotInNetwork --> <!-- in order to avoid relay check for locallly generated bounces --> <!-- <bind> </bind> --> <!-- Uncomment this if you want to use TLS (SSL) on this port --> <useTLS>true</useTLS>
RemoteManager
<remotemanager enabled="true"> <port>4555</port> <!-- Uncomment this if you want to bind to a specific inetaddress --> <!-- <bind> </bind> --> <!-- Uncomment this if you want to use TLS (SSL) on this port --> <useTLS>true</useTLS>
##问题 - 没法启动 查找文档须要安装ssl,并和http服务器去连接,超出范围。暂时不连接
#关于邮件收发的测试 ##未修改 - localhost A在本机登陆A@localhost 登陆正常
A@localhost 发送给 A@localhost 收发正常
B在外机登陆B@locahost 不能登陆
B在外机登陆B@A_IP 登陆征程
B@A_IP 发送给 A@localhost 收发正常 - 可是没法修改为B@localhost
##localhost修改成IP A在本机登陆A@localhost 登陆正常 A在本机登陆A@IP 登录正常 B在外机登陆B@IP 登录正常 A收发正常 B收发正常