本文根据ian f. darwin的«java cookbook»整理而成,原书用整章的文字介绍如何发邮件,可能头绪会比较乱,本文则将其浓缩成一篇文章,力求使完全不懂javamail的人,都可以根据文中指示稍作修改,拿来就可以用.如果对其中原理还有不清楚,你可以参考原书.
1.mailconstants.java,properties文件的助记符:///////////////////////////////////////////////////////////////////////package untitled2; 【程序编程相关:java:自己写的实现翻页功能的类】
一.首先要用到三个java文件: 【推荐阅读:acegi中的cache配置】
public static final string send_proto = "mail.send.protocol"; public static final string send_user = "mail.send.user"; public static final string send_pass = "mail.send.password"; public static final string send_root = "mail.send.root"; public static final string send_host = "mail.send.host"; public static final string send_debug = "mail.send.debug"; 【扩展信息:jsp+mysql制作简单的留言板(2)】
/** simply a list of names for the mail system to use. * if you "implement" this interface, you dont have to prefix * all the names with mailprops in your code. */public interface mailconstants { public static final string props_file_name = "mailclient.properties";
public static final string recv_proto = "mail.receive.protocol"; public static final string recv_port = "mail.receive.port"; public static final string recv_user = "mail.receive.user"; public static final string recv_pass = "mail.receive.password"; public static final string recv_root = "mail.receive.root"; public static final string recv_host = "mail.receive.host"; public static final string recv_debug = "mail.receive.debug";}///////////////////////////////////////////////////////////////////////
2.fileproperties.java,从文件中读取properties:///////////////////////////////////////////////////////////////////////package untitled2;
import java.io.*;import java.util.*;
/** * the <code>fileproperties</code> class extends <code>properties</code>, * "a persistent set of properties [that] can be saved to a stream * or loaded from a stream". this subclass attends to all the mundane * details of opening the stream(s) for actually saving and loading * the properties. * * <p>this subclass preserves the useful feature that * a property list can contain another property list as its * "defaults"; this second property list is searched if * the property key is not found in the original property list. * * @author ian f. darwin, ian@darwinsys.com * @version $id: fileproperties.java,v 1.5 2001/04/28 13:22:37 ian exp $ */public class fileproperties extends properties { protected string filename = null;
... 下一页