把JavaMail包装成简单的Sendmail


package steeven;

/*
Calss:  Sendmail
Author: steeven@kali.com.cn
QQ:     7461522
Date:   11/13/2001
Notes:
        Find samples in main();
        If you send mail only from/to intranet, change domain as u need.
Setup:
        1. change host, mailFooter
*/


import java.util.*;
import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class Sendmail extends Common{

  public String host = "smtpServer";              //smtp server
  static String mailFooter = "\n\n\n此邮件由WebMail发送 http://www/mail.jsp\n\n";
  String domain = "company";
  boolean sessionDebug;

  Message msg;
  Multipart multipart;

  public Sendmail() throws Exception{
    Properties props = System.getProperties();
    props.put("mail.host", host);
    props.put("mail.transport.protocol", "smtp");
    Session session = Session.getDefaultInstance(props, null);
    // Set debug on the Session so we can see what is going on
    // Passing false will not echo debug info, and passing true
    // will.
    session.setDebug(sessionDebug);
    // Instantiate a new MimeMessage and fill it with the
    // required information.
    msg = new MimeMessage(session);
    msg.setSentDate(new java.util.Date());
    multipart = new MimeMultipart();
    msg.setContent(multipart);
  }
  public Sendmail(String to, String from, String subject, String body) throws Exception{
    this();
    this.setSendTo(to);
    this.setFrom(from);
    this.setSubject(subject);
    this.setBody(body);
  }
  public Sendmail(String[] to, String from, String subject, String body) throws Exception{
    this();
    this.setSendTo(to);
    this.setFrom(from);
    this.setSubject(subject);
    this.setBody(body);
  }
  public void setHost(String host) throws Exception{
    this.host=host;
  }
  void setFrom(String from) throws Exception{
    msg.setFrom(new InternetAddress(from+"@"+domain));
  }
  void setSendTo(String[] to) throws Exception{
    for (int i=0;i
<淘宝热门商品:
 

 

伊人红妆赛维芦荟胶相宜本草昭贵田缘舞沙千纤草大宝庆琇郁美净

小小豆叮

0 Responses to "把JavaMail包装成简单的Sendmail"

发表评论