<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
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
|