WEB开发网
开发学院WEB开发Jsp 我常用的邮件发送类 阅读

我常用的邮件发送类

 2008-01-05 18:48:28 来源:WEB开发网   
核心提示:package javax.util.zz;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;import java.util.*;import java.net.*;import java.io.*;/** * <

package javax.util.zz;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
import java.net.*;
import java.io.*;


/**
 * <p>邮件发送类</p>
 * <p>支持普通模式和Html模式,可发送多个附件,支持SMTP服务器认证。<br>基于javamail开发,使用时请将javamail包含在classpath系统变量中。</p>
 * <p><br>使用说明:</p>
 * <p>Mail mail=new Mail();</p>
 * <p>mail.setXXX ....</p>
 * <p>mail.send();<br></p>
 * @author
 * @version 1.0
 */
public class Mail {

  PRivate Address[] to = null;
  private Address[] cc = null;
  private Address[] bcc = null;
  private String from = "";
  private String title = "";
  private String content = "";
  private String smtpHost = "";
  private int smtpPort = 25;
  private String content_type = MODE_TEXT;
  private String htmlMailDesc = "";

  private String smtpUser = "";
  private String smtpPassWord = "";
  private boolean isAuthenticationSMTP = false;

  private Vector vFiles = new Vector();
  private Vector vURLs = new Vector();

  public Mail() {
  }

  /**
  * 设置SMTP服务器,使用默认端口
  * @param server SMTP服务器ip
  */
  public void setSmtpHost(String server) {
   this.smtpHost = server;
  }

  /**
  * 设置SMTP服务器
  * @param server SMTP服务器IP
  * @param port 端口
  */
  public void setSmtpHost(String server, int port) {
   this.smtpHost = server;
   this.smtpPort = port;
  }

  /**
  * 设置收件人地址
  * @param aEmail 收件人Email地址
  */
  public void setTo(String aEmail) {
   String[] s = new String[1];
   s[0] = aEmail;
   this.to = getAddress(s);
  }

  /**
  * 设置多个收件人地址
  * @param Emails 收件人Email地址
  */
  public void setTo(String[] Emails) {
   this.to = getAddress(Emails);
  }

  /**
  * 设置抄送地址
  * @param aEmail 抄送地址
  */
  public void setCC(String aEmail) {
   String[] s = new String[1];
   s[0] = aEmail;
   this.cc = getAddress(s);
  }


Tags:常用 邮件 发送

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接