Introduction and basic configuration
James is an enterprise class mail server, it is fully realized, as well as smtp and nntp agreement pops (do not support IMAP). At the same time, james server is also a mail application platform. James is the core of Mailet API, and Qi is a james service mailet containers. It can be very easy for you to achieve a very powerful e-mail application. James open source projects have been widely used with the mail-related projects. Through which you can set up their own mail server. We can use Mailet API, programming interface required to achieve their own business. James integrates the Avalon application framework, as well as Phoenix Avalon Framework container. James server for the Phoenix provides a powerful support. Avalon should be noted that open-source projects have been shut down.
1.配置邮件服务器?
(1)设置服务器
<servernames autodetect="true" autodetectIP="true">
<servername>localhost</servername>
</servernames>
将localhost修改为你的服务器地址。
(2)设置邮件管理者的邮件地址
<postmaster>Postmaster@localhost</postmaster>
将localhost改成上面设置的服务器地址。
(3)设置验证
<authRequired>true</authRequired>
找到此行,去掉注释。
2.如何获取发送失败的错误信息?
打开文件SAF-INF/config.xml。
(1)找到<processor name="relay-denied" >,去掉以下行的注释。
<mailet match="All">
<attachment>none</attachment>
</mailet>
<mailet match="All"/>
(2)如果打开smtp authorized,去掉以下行的注释。
<mailet match="RemoteAddrNotInNetwork=127.0.0.1">
<processor> relay-denied </processor>
<notice>550 - Requested action not taken: relaying denied</notice>
</mailet>
3.增加用户?
telnet [邮件服务器地址] 4555
用户名:root (默认)
密码:root (默认)
使用addusers命令加入用户。 Other common commands:
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 关闭连接
Foxmail-mail account to test the use of open Foxmail, click on the "mail" -> "New Email Account"
E-mail address: chenfengcn @ localhost
Password is: 881213
POP3 server: localhost
SMTP server: localhost
The remaining options are to use the default, after the completion of the new, Foxmail will send a test message to our new mailbox, click on the "charge", we can e-mail account to collect e-mail inside the. Upon receiving the test Foxmail Send e-mail on the mail account that we normally use.
As programmers, we certainly hope to use their own written procedures to test whether our mail server to build a successful, rather than Foxmail. Let us use the following to achieve this Javamail it.
Database of user information storage
James e-mail user's user information stored in the default directory appsjamesvarusers, by modifying the configuration file appsjamesSAR-INFconfig.xml, user information can be saved to the database, configured as follows:
The first step: in the MySQL database to create a new mail, user name root, the password is blank;
Step two: open config.xml, find <users-store> this, the surface of the contents of the default as follows:
| <repository name="LocalUsers"> <destination URL="file://var/users/"/> </ repository> |
Need to be amended as follows:
| <repository name="LocalUsers" destinationURL="db://maildb/users"> <sqlFile> file: / / conf / sqlResources.xml </ sqlFile> </ repository> |
By way of an amendment, we put the user information storage medium from the file into a db, <sqlFile> are specified in the db table structure of data and related database information.
Step three: still config.xml, find <data-sources>, the default content is empty, the contents of this amended to read:
| <data-source name="maildb"> <driver> org.gjt.mm.mysql.Driver </ driver> <dburl> jdbc: mysql: / / 127.0.0.1/mail </ dburl> <user> root </ user> <password> </ password> <max> 20 </ max> </ data-source> |
MySQL is the <driver> the JDBC driver, <dburl> refers to the path of the database access, IP of the mail after that in the new MySQL database name, followed by user name, password, and the largest number of connections.
Thus, the database configuration completed, restart James, if properly, please telnet to add a new user, such as adduser holen 123456, and then check the mail in the MySQL database, the following will have a table users, this is James in accordance with file: / / conf / sqlResources.xml created content.
Through the above configuration, James user information can be stored in a database.
Password problem
When you add a new user through telnet when, for example, adduser holen 123456, you can view the database records, the first field is holen, the second field is the password, but password is not 123456, and a bunch of "garbage" (zhwQUMTwdMqWfm / h0biB51Gf)?? This is the password password plus content, look at the back of the field is "SHA", apparently using SHA encryption.
Telnet way through to add new users, user passwords will be automatically encrypted, and then inserted into the database. Way through telnet user management has a lot of inconvenience, even though you can use one of James Toolkit RMI, improve efficiency, there is still no change in the nature where there is a need for commercial purposes, you can not ask you to remember that customers at the command stack.
General we can do a Web front-end, through the form page, add the amendments to the user, user-friendly, fool of use, such as 263 or 163 of the same. Doing so, we need to direct operation of the database, add users to delete records or modify the user record. But do not forget, James default user password is encrypted, since we have to direct operation of the database, then we have only two options: either we have studied the mechanism of their password, add the record, we have the new user's password to perform the same encryption, Either we remove the encryption mechanism for James to save code.
Fortunately, these two options are feasible. We downloaded from the Apache source code package James, download the document after the james-2.1-src.zip, close to 8M, by analyzing the source code, we found that the relevant documents the user's password is DefaultUser.java, some source code is as follows :
| package org.apache.james.userrepository; ... ... / ** * Method to verify passwords. * * @ Param pass the String that is claimed to be the password for this user * @ Return true if the hash of pass with the current algorithm matches * The stored hash. * / public boolean verifyPassword (String pass) ( try ( String hashGuess = DigestUtil.digestString (pass, algorithm); return hashedPassword.equals (hashGuess); ) Catch (NoSuchAlgorithmException nsae) ( throw new RuntimeException ( "Security error:" + nsae); ) ) / ** * Sets new password from String. No checks made on guessability of * Password. * * @ Param newPass the String that is the new password. * @ Return true if newPass successfuly hashed * / public boolean setPassword (String newPass) ( try ( hashedPassword = DigestUtil.digestString (newPass, algorithm); return true; ) Catch (NoSuchAlgorithmException nsae) ( throw new RuntimeException ( "Security error:" + nsae); ) ) ... ... |
The first method verifyPassword () is used to do password authentication, incoming parameter is the cleartext password, through DigestUtil.digestString () method to convert ciphertext password, database password and then compare the results to return. Please note here DigestUtil.digestString () method, also referred to in the back.
The second method setPassword () is used to convert the password to explicitly into ciphertext using the same DigestUtil.digestString () method.
Here, I believe you should know how to program in their own conversion and password for password authentication of it! In fact, not one to write your own encryption algorithm SHA, as James has already provided this feature, you call and that was it.
There is also a situation, the needs of developers in the database must be explicitly saved passwords, so that you do not write in their own password in the conversion process, and when the number of applications using a unified user model, the best example there is only one user. To achieve this demand, we can only modify the source code of the James, the verifyPassword () and setPassword () changed to:
| public boolean verifyPassword (String pass) ( return hashedPassword.equals (pass); ) public boolean setPassword (String newPass) ( hashedPassword = newPass; return true; ) |
In fact, the conversion process is to remove, preserve and certification specifically for use on the.
If you feel that way is wrong with SHA and other encryption methods can be articulated, is to amend the two methods.
Note that when you modify the source code of the James, you need to use Ant to build James project, build will be in james-2.1-srcdistjames-2.1apps below to find a new documents james.sar generated. James covered the original document james.sar, and delete at the same level with the james.sar directory james, james can restart. Proposed to retain the original config.xml, so also with the first.
Explore the above, we understand how the adoption of Web-user registration and user registration. Should be noted that, James automatically generated table of users, only 7 fields, and are used by system needs. General registration information is necessary to import more items, then proposed their own developers to build a new table USERINFO, with username associated with the two tables, users do not propose to amend the contents of the table (if you want to try, please refer to file: / / Conf / sqlResources.xml).
-------------------------------------------------- -------------------------------------------------- ----------------------------
It plainly is to copy the code from there, to write an explicit way to ciphertext, as follows:
package struts.action;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;
//用作SHA加密
public class PwdSecurity {
public static String digestString(String pass, String algorithm)
throws NoSuchAlgorithmException {
MessageDigest md;
ByteArrayOutputStream bos;
try {
md = MessageDigest.getInstance(algorithm);
byte[] digest = md.digest(pass.getBytes("iso-8859-1"));
bos = new ByteArrayOutputStream();
OutputStream encodedStream = MimeUtility.encode(bos, "base64");
encodedStream.write(digest);
return bos.toString("iso-8859-1");
} catch (IOException ioe) {
throw new RuntimeException("Fatal error: " + ioe);
} catch (MessagingException me) {
throw new RuntimeException("Fatal error: " + me);
}
}
}
Have the following error:
Reasons: javax.mail and javax.activation these two packages have been javaEE5 which are based on a package that comes with the JDK has been in, but the way it is now outside the mail.jar and activation.jar were some discrepancies
Solution: enter into
X: / Program Files / MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.eclipse.j2eedt.core_6.0.1.zmyeclipse601200710/data/libraryset/EE_5/javaee.jar
(Note that I use 6.0)
This path, we can see javaee.jar, using rar to open the document, and then into the javax folder, delete the mail.jar and activation.jar (my javaee.jar years, these two things folder In short deleted on OK, but you should pay attention to the backup







