首先引入j2ee的包路径到ClassPath,已经安装Jbuilder的可以在它的安装路径lib目录下找
到mail.jar,activation.jar,将这两个包加入系统的环境变量,那么即使不用JBuilder开发的话也可以
使用了.
程序:
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/**
*
Title: 简易MailBean
*
Description: 提供简便的Mail发送功能(/p>
*
Copyright: Copyright (c) 2003
* @version 1.0
*/
class ExtendString {
public ExtendString() {
}
/**
去掉字符串两端的空白字符,并将字符串转化为中国的标准字符gb2312的字符串.
*/
public String CS(String str) { //去掉字符串2端的空白字符
try {
if (str == null)
return "";
str = str.trim();
if (str == null)
return "";
str = new String(str.getBytes("8859_1"), "GBK");
}
catch (Exception e) {
System.out.println(e);
}
return str;
}
}
public class SendMail
{
private String errMsg = "";
private ExtendString ExStr = new ExtendString();
private String sender = "";//发件人地址
private String smtpHost = "";//邮件发送服务器(smtp)
private String user = ""; //登录用户名
private String password = "";//登录密码
private String subject = "";//mail主题
public SendMail()
{
this.setPropertiesAttri();
}
private void setPropertiesAttri()
{
try
{
InputStream is = getClass().getResourceAsStream("MailServer.properties");
Properties prop = new Properties();
prop.load(is);
this.setSmtpHost(prop.get("SmtpHost").toString());