侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Apache James简单邮件服务器配置

2023-12-22 星期五 / 0 评论 / 0 点赞 / 154 阅读 / 16691 字

#编者注之前的老系统使用的是windows上的hmail服务器,由于界面感官好,配置迅速,则为了上线使用。但度过了3年左右,原始配置hmail的人员离职。并且由于Windows的问题,并不能够和Lin

#编者注之前的老系统使用的是windows上的hmail服务器,由于界面感官好,配置迅速,则为了上线使用。但度过了3年左右,原始配置hmail的人员离职。并且由于Windows的问题,并不能够和Linux系统上的软件打包。并且,由于近期断电事故导致风险加剧。所以,需要搭建简单易用的Mail服务器。

#Apache JamesApache James项目提供了一组丰富的开放源代码的模块和库,由Java编写,互联网邮件通信建设成为先进的企业邮件服务器相关。

#下载James

#JAVA_HOME[20161102]由于本人第二次的是使用的是mac系统,安装的JDK8,James找不到JAVA_HOME。需要在James当中添加。##JAVA_HOME添加到run.sh - 失败由于James通过bin/run.sh运行,首先尝试的是在run.sh中添加JAVA_HOME,如下内容是在run.sh头部进行添加

# -- 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/HomeERROR: JAVA_HOME not found in your environment.Please, set the JAVA_HOME variable in your environment to match thelocation of the Java Virtual Machine you want to use.

确认,实际的James的执行是使用phoenix.sh进行执行##JAVA_HOME添加到phoenix.sh在bin/phoenix.sh添加JAVA_HOME

# -- zhanpeng for mac config JAVA_HOME--JAVA_HOME=`/usr/libexec/java_home`

运行结果

vfxdeiMac:bin zhanpeng$ ./run.sh /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/HomeUsing PHOENIX_HOME:   /Users/zhanpeng/build/james/james-2.3.2.1Using PHOENIX_TMPDIR: /Users/zhanpeng/build/james/james-2.3.2.1/tempUsing JAVA_HOME:      /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/HomeRunning Phoenix: Phoenix 4.2James Mail Server 2.3.2.1Remote Manager Service started plain:4555

#Component named "pop3server" failed to pass through the Starting stageMac和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注释掉,替换成数据库repository

<!--      <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的格式配置

      <!-- 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.jarjames-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/HomeUsing PHOENIX_HOME:   /Users/zhanpeng/build/james/james-2.3.2.1Using PHOENIX_TMPDIR: /Users/zhanpeng/build/james/james-2.3.2.1/tempUsing JAVA_HOME:      /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/HomeRunning Phoenix: Phoenix 4.2James Mail Server 2.3.2.1Remote Manager Service started plain:4555POP3 Service started plain:110SMTP Service started plain:25NNTP Service started plain:119FetchMail 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配置为JDBCSpool 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&gt;</prompt>         -->      </handler>   </remotemanager>

#telnet登录并添加用户

vfxdeiMac:SAR-INF zhanpeng$ telnet localhost 4555Trying ::1...Connected to localhost.Escape character is '^]'.JAMES Remote Administration Tool 2.3.2.1Please enter your login and passwordLogin id:rootPassword:!changeme!Welcome root. HELP for a list of commandshelpCurrently implemented commands:help                                    display this helplistusers                               display existing accountscountusers                              display the number of existing accountsadduser [username] [password]           add a new userverify [username]                       verify if specified user existdeluser [username]                      delete existing usersetpassword [username] [password]       sets a user's passwordsetalias [user] [alias]                 locally forwards all email for 'user' to 'alias'showalias [username]                    shows a user's current email aliasunsetalias [user]                       unsets an alias for 'user'setforwarding [username] [emailaddress] forwards a user's email to another email addressshowforwarding [username]               shows a user's current email forwardingunsetforwarding [username]              removes a forwarduser [repositoryname]                   change to another user repositoryshutdown                                kills the current JVM (convenient when James is run as a daemon)quit                                    close connectionadduser wangyinghan 123User wangyinghan added

#使用thunderbird链接异常提示

接收:POP3,xxx,未加密发送:SMTP,xxx,未加密用户名:xxx

查询James文档,得知需要修改useTLS值为sslPOP3

<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服务器去链接,超出范围。暂时不链接

#关于邮件收发的测试##未修改 - localhostA在本机登录A@localhost 登录正常
A@localhost 发送给 A@localhost 收发正常
B在外机登录B@locahost 不能登录
B在外机登录B@A_IP 登录征程
B@A_IP 发送给 A@localhost 收发正常 - 但是无法修改成B@localhost

##localhost修改为IPA在本机登录A@localhost 登录正常
A在本机登录A@IP 登陆正常
B在外机登录B@IP 登陆正常
A收发正常
B收发正常

广告 广告

评论区