[Practice has proved that finishing line] CentOS 6 in the easy set up Apache James mail server

2011-09-23  来源:本站原创  分类:OS  人气:128 

Reference

1 set up with Apache James mail server to send and receive e-mail practices (a)

http://zhaipuhong.iteye.com/blog/213246

2. James + mysql

http://godchenmeng.iteye.com/blog/516680

3. Apache James user information database to store and password problems

http://jetway.iteye.com/blog/608808

4 using javamail to send email with attachments

http://redleaf.iteye.com/blog/78217


Order

Network resources, but I do not know why, when I follow the online step by step technical articles after the result is always failure, the problem re out.

And the world is a big copy the article, through the search results got mostly the same.

Decided to record their own step by step clear of the operation, summarized the article, to facilitate his own future reference, may also be helpful to others.

Purpose

In James CentOS install and configure the mail service, complete the e-mail (send and receive local and external network because there is no domain name resolution can only send, not receive).

Operating environment

Server hardware: EeePC 701 (super bad configuration)

Server system: CentOS 6

Java: java 1.7.0

James: James Mail Server 2.3.2

JMail API: javamail-1.4.4

Client test system: windows 7

Client test development tools: eclipse 3.6 for J2EE

Step

1 download, install, configure JDK

This is no longer described, please refer to other documents, or documents mentioned in the other.

2 download, install, James

Here ( http://james.apache.org/ ) can be found for download.

In this article installed James Server 2.3.2.

Downloaded apache-james-2.3.2.zip file by the unzip command will extract to a James feel right place.

#unzip apache-james-2.3.2.zip -d /home/aclyyx/

Can be "/ home / aclyyx /" into the position you want

Unzip get james-2.3.2 folder, this installation is complete, in fact, a decompression process.

3 James server is first started

James started service needs root privileges, otherwise it will throw an exception: "java.net.BindException: insufficient privileges."

Into the bin directory james, there are several sh file, first to give execute permission.

#chmod 777 *.sh

After the implementation of the run.sh file.

#./run.sh

Service starts successfully, will display the following information:

Using PHOENIX_HOME:   /home/aclyyx/james-2.3.2
Using PHOENIX_TMPDIR: /home/aclyyx/james-2.3.2/temp
Using JAVA_HOME:      /usr/java/jdk1.7.0
Running Phoenix:

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 on CentOS might fail to start the next, which may result because the port is occupied. Use the netstat command to see which port is occupied, and then modify the configuration does not use James occupied port.

(Mentioned later in the configuration)

Check whether the port is occupied

#netstat -pan|grep 25

4 Configure James

"Ctrl + C" to James Service stopped.

(The following text taken from here)

Server starts, the machine will be configured in a default service, which can be used in the machine within the server send and receive mail.

Open the James directory \ apps \ james \ SAR-INF under the config.xml file, James first started, it will not have this file, only when James after service starts automatically once the file components.

Found

--
<postmaster>[email protected]</postmaster>
--
<servernames autodetect="true" autodetectIP="true">
    <servername>aclyyx.com</servername>
</servernames>
--

To the localhost as the domain name you want mail to automatically detect IP properties are set to "false" is assumed if the change zhaipuhong.com opened an account zph, then his e-mail address is [email protected] (^ _ ^) modified as follows:

--
<postmaster>[email protected]</postmaster>
--
<servernames autodetect="false" autodetectIP="false">
    <servername>zhaipuhong.com</servername>
</servernames>
--

Found

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

To note the following results:

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

Find the following elements, remove the comments

<authRequired>true</authRequired>

This access requires account verification email, you do not want others to send and receive messages using your account right ... ... ^ _ ^
So, James service configuration has been completed.

(Above text taken from the surface here)

Here to talk about the previously mentioned port configuration conflicts, it is also in the config.xml file, search out the port number, and modify as desired port number.

5 Open Firewall

Open / etc / sysconfig / iptables file

#vi /etc/sysconfig/iptables

Before the REJECT line add the following code

-A INPUT-m state - state NEW-m tcp-p tcp - dport 110-j ACCEPT
-A INPUT-m state - state NEW-m tcp-p tcp - dport 26-j ACCEPT
-A INPUT-m state - state NEW-m tcp-p tcp - dport 4555-j ACCEPT
-A INPUT-m state - state NEW-m tcp-p tcp - dport 119-j ACCEPT

Save and close the file, restart the Firewall

#service iptables restart

6. And then start the James server, e-mail account management

Again using the root user to run the run.sh file services start James.

#./run.sh

James can be achieved through the mail service manager's management. James Manager is a remote connections via telnet protocol manager.

#telnet 127.0.0.1 4555

In the Manager provides many features, view users, add and delete users and so on. help about

(Excerpt from the next things to text here)

-------------------------------------------------- ----------------------------------

help display this help Display help information
listusers display existing accounts show the current account
countusers display the number of existing accounts show the number of existing accounts
adduser [username] [password] add a new user to add a new user
verify [username] verify if specified user exist to verify the existence of the specified user
deluser [username] delete existing user to delete existing users
setpassword [username] [password] sets a user's password set user password
setalias [user] [alias] locally forwards all email for 'user' to 'alias' set mail alias
showalias [username] shows a user's current email alias show alias
unsetalias [user] unsets an alias for 'user' to delete the user alias
setforwarding [username] [emailaddress] forwards a user's email to another email address to forward the user's e-mail address to another email address
showforwarding [username] shows a user's current email forwarding display the user's current e-mail forwarding
unsetforwarding [username] emoves a forward delete forwarding
user [repositoryname] change to another user repository to change another user library
shutdown kills the current JVM (convenient when James is run as a daemon) to close the current service
quit close connection closed connection

-------------------------------------------------- ----------------------------------

(Above text taken from the surface here)

This creates two users, easy to use after testing.

#adduser acl1 111111
#adduser acl2 222222

7. Download JavaMail API

JavaMail, by definition, available to developers to handle e-mail-related programming interface. Sun announced it is to handle the email API. It is easy to perform some commonly used mail transfer. We can develop a JavaMail-based applications like Microsoft Outlook.

(Above the surface of the text from Baidu Baike )

JavaMail can go here for download, download get javamail1_4_4.zip, is the package to the lib directory of the jar package file. Extract them into the development environment can be.

8 e-mail client development

The following procedure only a few modifications, the other blog for the source code.

The test program can be achieved by the multi-user network to send and receive mail, the same can also be achieved through small changes outside network to send mail. Can modify the "e-mail recipient's e-mail address" as [email protected] to the external network to send mail. Do not know what Gmail can receive mail, but mail is not 126.

package mail;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

public class HelloJMail {  

    //  Send e-mail
    public static void sendMail() {
        //String host = "192.168.1.98"; //   Specified smtp server  ,  Local LAN  IP
        String host = "192.168.11.200"; //   Local smtp server
        String from = "[email protected]"; //   Sender's email address
        String to = "[email protected]"; //   E-mail address of the recipient's e-mail
        final String username = "acl1";  //  Sender's mail account
        final String password = "111111";   //  Sender's e-mail password    

        //   Create Properties object
        Properties props = System.getProperties();  

        //   Added smtp server properties
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.port", "26");
        props.put("mail.smtp.auth", "true");  

        //   Create a mail session
        Session session = Session.getDefaultInstance(props, new Authenticator(){
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }

        });  

        try {
            //   Definition of e-mail message
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject(transferChinese("  I have my own mail server of the  "));

            Multipart mp = new MimeMultipart();
            MimeBodyPart mbp = new MimeBodyPart();
            mbp.setContent("rt,  I have my own mail server of the  ", "text/html;charset=gb2312");
            mp.addBodyPart(mbp);    

            //  Add Attachment
//            mbp=new MimeBodyPart();
//            String filename= "G:\\hi.txt"; //  Choose a name for each attachment
//            FileDataSource fds = new FileDataSource(filename); //  Get data source
//            mbp.setDataHandler(new DataHandler(fds)); //  Into itself and to the Annex  BodyPart
//            mbp.setFileName(fds.getName());  //  To get into the same file name  BodyPart
//            mp.addBodyPart(mbp);

            message.setContent(mp);

            //   Send a message
            session.getTransport("smtp").send(message);
            //Transport.send(message); // Create a Transport object that can send
            System.out.println("SendMail Process Over!");  

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }  

    //  Receiving e-mail
    public static void getMail(){
        String host = "192.168.11.200";
        final String username = "acl2";
        final String password = "111111";  

        //   Create Properties object
        Properties props = new Properties();  

        //   Create a mail session
        Session session = Session.getDefaultInstance(props, new Authenticator(){
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }  

        });  

        try {
            //   Pop3 mailbox store to get
            Store store = session.getStore("pop3");
            store.connect(host, username, password);  

            //   Access inbox files
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);  //  Open, read the message before opening    

            //   Get e-mail messages
            Message message[] = folder.getMessages();  

            for (int i=0, n=message.length; i<n; i++) {
                System.out.println(i + ": " + message[i].getFrom()[0]
                                               + "\t" + message[i].getSubject());
                try {
                    message[i].writeTo(System.out);
                } catch (IOException e) {
                    e.printStackTrace();
                }  

            }  

            //   Close Resources
            folder.close(false);
            store.close();  

        } catch (MessagingException e) {
            e.printStackTrace();
        }  

        System.out.println("GetMail Process Over!");  

    }  

    //  Subject Chinese character conversion
    public static String transferChinese(String strText){
        try{
            strText = MimeUtility.encodeText(new String(strText.getBytes(), "GB2312"), "GB2312", "B");
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return strText;
    }  

    public static void main(String[] args) {
        HelloJMail.sendMail();
        //HelloJMail.getMail();
    }
}

9 e-mail users with a MySQL database management

Mail system is not user management console with unfriendly words to complete, but beautiful and convenient graphical management interface, or simply as the famous 126 is open for registration.

Obviously, this is not what we want, we can first try the user information into a database to manage.

First installed MySQL, will explain in other places; or your 100 Valley about.

To facilitate the management, to create a database in MySQL "maildb", then a new MySQL user "mailuser".

Download the MySQL JDBC driver package, and placed James in the lib directory under the directory.

James once again to open the config.xml configuration file

#vi james\apps\james\SAR-INF\config.xml

Found

--
<repository name="LocalUsers">
   <destination URL="file://var/users/"/>
</repository>
--

The comments, add the following configuration

--
<repository name="LocalUsers" destinationURL="db://maildb/users">
   <sqlFile>file://conf/sqlResources.xml</sqlFile>
</repository>
--

Then search for the file "data-source", find the following configuration

--
<data-source name="maildb">
   <driver>org.gjt.mm.mysql.Driver</driver>
   <dburl>jdbc:mysql://127.0.0.1/maildb</dburl>
   <user>mailuser</user>
   <password>1234</password>
   <!--poolPreparedStatements>true</poolPreparedStatements-->
   <max>20</max>
</data-source>
--

Release notes, and modify the configuration of which corresponds to the database information.

James again launched service program.

#./run.sh

OK, James will create a database in maildb "users" table.

Can also telnet ugly text console adduser, create a user and then to a MySQL database select it.

select * from users;

In the users table will have a newly created user, the same, you can also insert records into the users table to create a new user.

相关文章
  • [Practice has proved that finishing line] CentOS 6 in the easy set up Apache James mail server (continued 1) - into the database of users and e-mail 2011-09-28

    Reference 1. James + mysql http://godchenmeng.iteye.com/blog/516680 2. MYSQL user rights management (Grant, Revoke) http://read.newbooks.com.cn/info/197474.html Order Network resources, but I do not know why, when I follow the online step by step tec

  • [Practice has proved that finishing line] CentOS 6 in the easy set up Apache James mail server 2011-09-23

    Reference 1 set up with Apache James mail server to send and receive e-mail practices (a) http://zhaipuhong.iteye.com/blog/213246 2. James + mysql http://godchenmeng.iteye.com/blog/516680 3. Apache James user information database to store and passwor

  • [Practice has proved that finishing line] vsFTPd installation and configuration 2011-09-21

    Reference 1. VsFTPd configuration: http://www.centos.bz/2011/03/centos-install-vsftpd-ftp-server/ 2. Centos user & group permissions to add and delete users & Detailed questions: http://zh888.blog.51cto.com/1684752/385605 3. Setsebool command: htt

  • [Practice has proved that finishing line] TP-LINK TL-PA201 Power Line Adapter Utility 2011-10-08

    Reference Some use refer to the original article Jingdong Products http://www.360buy.com/product/277420.html Order Network resources, but I do not know why, when I follow the online step by step technical articles after the result is always failure,

  • CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration process will be recorded & & apache installed as system services 2011-03-16

    Quote CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration record & & the apache installed as system services collections environment: This article in the Linux operating system is CentOS 5.2, Linux 2.6 + kerne

  • Sendmail mail server set up and configure CentOS 2011-04-13

    View Installation rpm-qa | grep sendmail rpm-qa | grep dovecot rpm-qa | grep cyrus Install the mail server yum install sendmail sendmail-cf Installation pop3/imap Service yum install dovecot installed user authentication yum install cyrus-sasl yum in

  • CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL) 2014-04-19

    这篇文章主要介绍了CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)的方法,需要的朋友可以参考下 准备篇: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙 -A INPUT -m state --state NEW -m tcp -p tcp --dport 33

  • CentOS 6.2安装配置LAMP服务器(Apache+PHP5+MySQL) 2012-12-16

    CentOS 6.2安装配置LAMP服务器(Apache+PHP5+MySQL) 准备篇: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙) -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过

  • CentOS 5.3 on a yum install Apache + php + Mysql + phpMyAdmin 2010-05-07

    Centos in the yum-line installation is slow. The following are replacement for Chinese CentOS mirror server! The official mirror sites: http://centos.ustc.edu.cn/ / * Instructions * / cd / etc / yum.repos.d [enter yum.repos.d directory] mv CentOS-Bas

  • CentOS install one more: Easy to install Virtual Machine 2010-05-06

    OK, now, thanks to virtual machine technology with a dual system on the provinces, so the next thing in my colleagues asked, found a small virtual machine: Sun VirtualBox, use what feels good ~ ~ good, not crap started install linux virtual machines

  • CentOS Linux system to automatically uninstall the apache 2011-05-22

    Apache CentOS system automatically uninstall View the system has no built Apache software, the command is as follows: Quote [Root @ localhost local] # rpm-qa | grep httpd httpd-2.2.3-43.el5.centos Description: rpm-qa | grep httpd command is related t

  • Centos 5.5 configuration independent Subversion 1.6.12 (SVN) server 2011-04-15

    subversion (hereinafter referred to as svn) version of the rise in recent years, management tools, is the successor to cvs. svn server has two possible modes: 1. Standalone server 2 with apache. Two ways have advantages and disadvantages, can be conf

  • 在CentOS 6 中安装WordPress(一) 安装Apache,Mysql, PHP环境 2014-05-11

    最近做个项目,拿到一台CentOS 6服务器,需要在上面配置php环境,并安装WordPress,我们先来看看第一步,配置AMP(Apache,Mysql, PHP)环境 1.安装Apache 在终端中输入下面的命令就可以安装Apache了: sudo yum install httpd sudo的意思是用root用户做什么操作.要点击y就确认下载安装了,非常方便. 然后用下面的命令来启动服务 sudo service httpd start 现在不用着急往下弄,直接在浏览器中输入Digital

  • Java Products and software download 2009-03-13

    This column provides hundreds of Java products and software download site link and brief introduction developerWorks Web site resources related technologies. Through this column, you can easily find you need Java tools, components and code, but also

  • linux learning route 2010-02-03

    Linux road map learning: understanding of Linux-based Zhi Shi; Zhangwo commands more than 50 Chang Yong; master. Tgz,. Rpm Deng package installation method; study add peripheral, install device drivers; Shuxi Linux File systems, and directory Jiegou

  • 11:00 Learning Linux system recommendations 2010-08-07

    With the expansion of Linux applications, many friends came into contact with Linux, according to the experience of learning Windwos often some loss of feeling: I do not know where to begin to learn the. How to get online help and a proprietary opera

  • Apache open source project classification list 2009-10-13

    Original link: http://blog.chinaunix.net/u/21477/showart_265148.html Apache open source project classification list Categories Project name Description The development of language Server (20) Apache HTTP Server HTTP server first in the world C / C +

  • James Server Configuration (2) 2010-07-27

    James server started Double-click \ james-2.3.1 \ bin directory run.bat file to launch the James server. Console displays the following: Using PHOENIX_HOME: F: \ Projects \ James \ james-2.3.1rc1 Using PHOENIX_HOME: F:\ Project \James\james-2.3.1rc1

  • Grasp the depth of NFS server 2010-09-30

    For the NFS server, you may already have mastered. But you really do learn it? Knowledge of many details may have been overlooked. It does not matter, this paper will we do about the specific summary. We want to help. NFS is the Network File System (

  • Apache open source project category list 2011-01-12

    Categories Project Name Help Development of language Servers (20) Apache HTTP Server HTTP server is the world's first C / C + + Tomcat Java Web Server Java James Mail server Java SpamAssassin Anti-Spam C / C + + Perl The Perl programming language sup