首页 > 其他分享 >Apache James 系列1 --- 安装

Apache James 系列1 --- 安装

时间:2023-02-14 23:24:48浏览次数:52  
标签:opt James 配置 --- apache https james Apache com

一、环境

1. 版本

(1) CentOS 7.9 2009;

(2) Apache James 3.6.2;

(3) 域名:假设我们使用test.com作为我们的邮箱域名。

2. 准备

(1) 下载

可前往https://james.apache.org/download.cgi查看最新的版本:

wget https://dlcdn.apache.org/james/server/3.6.2/james-server-app-3.6.2-app.zip

(2) 创建安装目录

sudo mkdir -p /opt/apache-james

(3) 解压

sudo unzip james-server-app-3.6.2-app.zip -d /opt/apache-james
sudo mv /opt/apache-james/james-server-app-3.6.2/* /opt/apache-james
sudo rm -rf /opt/apache-james/james-server-app-3.6.2

二、安装

Apache James是使用Java编写的程序,解压包中核心是lib目录下的james-server-app-3.6.2.jar文件,无需使用yum install命令安装,我们需要做的是修改其相关配置。

1. 域名配置

(1) 编辑配置

sudo vi /opt/apache-james/conf/domainlist.xml

(2) 配置域名

<!-- JPA implementation for DomainList -->
<domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
   <autodetect>false</autodetect>
   <autodetectIP>false</autodetectIP>
   <defaultDomain>test.com</defaultDomain>
</domainlist>

需要将配置中的defaultDomain改为自己的域名。

如果该James实例需要同时支持多个不同的域名,则需要配置domainnames节:

<domainlist class="org.apache.james.domainlist.xml.XMLDomainList">
   <domainnames>
       <domainname>mail1.com</domainname>
       <domainname>mail2.com</domainname>
   </domainnames>
   <autodetect>true</autodetect>
   <autodetectIP>true</autodetectIP>
   <defaultDomain>test.com</defaultDomain>
</domainlist>

2. MySQL配置

(1) 编辑配置

sudo vi /opt/apache-james/conf/james-database.properties

(2) 配置MySQL

Apache James默认使用DERBY数据库来存储邮件数据,我们需要将其默认数据库链接注释,并添加新的MySQL配置;

a. 注释以下配置

#database.driverClassName=org.apache.derby.jdbc.EmbeddedDriver
#database.url=jdbc:derby:../var/store/derby;create=true
#database.username=app
#database.password=app

b. 修改以下配置

# Supported adapters are:
# DB2, DERBY, H2, HSQL, INFORMIX, MYSQL, ORACLE, POSTGRESQL, SQL_SERVER, SYBASE 
vendorAdapter.database=MYSQL

c. 添加MySQL配置

database.driverClassName=com.mysql.cj.jdbc.Driver
database.url=jdbc:mysql://127.0.0.1:3306/james?useUnicode=true&useSSL=false&characterEncoding=UTF-8&rewriteBatchedStatements=true&allowMultiQueries=true&serverTimezone=UTC
database.username=[UserName]
database.password=[Password]

注意修改MySQL的服务器IP地址、账号和密码。

(3) 下载MySQL的Java驱动

wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.30/mysql-connector-java-8.0.30.jar
sudo mv mysql-connector-java-8.0.30.jar /opt/apache-james/lib

3. Mailet配置

(1) 编辑配置

sudo vi /opt/apache-james/conf/mailetcontainer.xml

mailetcontainer.xml由若干处理器(processor)组成,每个处理器都负责实现相应的功能。

(2) 管理员邮箱

    <!-- MailAddress used for PostMaster -->
    <context>
        <!-- When the domain part of the postmaster mailAddress is missing, the default domain is appended.
        You can configure it to (for example) <postmaster>[email protected]</postmaster> -->
        <postmaster>[email protected]</postmaster>
    </context>

这里是配置邮箱管理员账号的地方,注释告诉我们,如果我们不填写@后的域名部分,我们在domainlist.xml中配置的defaultDomain将被作为默认的管理员邮箱域名,合起来就是:

postmaster@localhost

(3) 错误处理器

当出现非预期的错误时,将会调用该错误处理器:

    <processor state="error" enableJmx="true">
       <!-- If you want to notify the sender their message generated an error, uncomment this       -->
       <!--
       <mailet match="All" class="Bounce"/>
         -->
       <!-- If you want to notify the postmaster that a message generated an error, uncomment this  -->
       <!--
       <mailet match="All" class="NotifyPostmaster"/>
         -->

       <!-- Logs any messages to the repository specified -->
       <mailet match="All" class="ToRepository">
          <!-- <repositoryPath>file://var/mail/error/</repositoryPath> -->
          <!-- An alternative database repository example follows. -->
          <repositoryPath>db://maildb/deadletter/error</repositoryPath>
       </mailet>
    </processor>

(4) 注销RemoteAddrNotInNetwork所在行

       <!-- 
       <mailet match="RemoteAddrNotInNetwork=127.0.0.1" class="ToProcessor">
          <processor>relay-denied</processor>
          <notice>550 - Requested action not taken: relaying denied</notice>
       </mailet>
       -->

4. SMTP配置

(1) 编辑配置

sudo vi /opt/apache-james/conf/smtpserver.xml

(2) helloname

在"smtpservers->smtpserver"下找到已经被注释的"helloName"节点,解开其注释并配置它的值为邮箱服务域名

        <!-- This is the name used by the server to identify itself in the SMTP -->
        <!-- 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">test.com</helloName>

(3) SMTP认证

在"smtpservers->smtpserver"下找到已经被注释的"authRequired"节点,解开其注释:

        <authRequired>true</authRequired>

(4) 发件人地址校验

在"smtpservers->smtpserver"下找到已经被注释的"verifyIdentity"节点,解开其注释:

<verifyIdentity>true</verifyIdentity>

该配置用于校验己方发件人的地址信息。

5. LDAP 配置

我们使用LDAP的用户作为我们收发邮件的用户,也就是Apache James的用户。

(1) 编辑配置

sudo vi /opt/apache-james/conf/usersrepository.xml

(2) 注释掉原有的usersrepository块:

注意,在添加注释之前,usersrepository块内部也有注释,所以这里可以把整个块删除,也可以分别添加两段注释。

(3) 在usersrepository块下方添加以下配置:

<!-- Read-Only LDAP based UsersRepository -->
<repository name="LocalUsers" 
    class="org.apache.james.user.ldap.ReadOnlyUsersLDAPRepository" 
    ldapHost="ldap://127.0.0.1:389" 
    principal="cn=admin,dc=example,dc=com" credentials="password"
    userBase="ou=People,dc=example,dc=com" userIdAttribute="uid"
    userObjectClass="inetOrgPerson" maxRetries="20" retryStartInterval="0" retryMaxInterval="30" retryIntervalScale="1000">
        <UsersDomain>example.com</UsersDomain>  
        <LDAPRoot>dc=example,dc=com</LDAPRoot> 
        <MailAddressAttribute>mail</MailAddressAttribute> 
        <IdentityAttribute>uid</IdentityAttribute> 
        <AuthenticationType>simple</AuthenticationType>
        <ManagePasswordAttribute>TRUE</ManagePasswordAttribute> 
        <PasswordAttribute>userPassword</PasswordAttribute> 
</repository>

6. 运行

sudo chmod +x /opt/apache-james/bin/run.sh
/opt/apache-james/bin/run.sh

四、参考

1. 官方

https://james.apache.org/server/config.html

2. 其他

https://blog.csdn.net/qq_29427355/article/details/127083676

https://robertmunn.com/blog/installing-apache-james-email-server-on-ubuntu/

https://robertmunn.com/blog/building-and-configuring-apache-james-with-openldap/

https://robertmunn.com/blog/configuring-ssl-in-apache-james/

https://nozaki.me/roller/kyle/entry/installing-james-as-a-service

https://serverfault.com/questions/408758/using-apache-james-mail-server-with-ldap

标签:opt,James,配置,---,apache,https,james,Apache,com
From: https://www.cnblogs.com/eagle6688/p/17093139.html

相关文章