import java.util.*;
import java.io.*;import javax.mail.*;
import javax.mail.internet.*;import javax.activation.*;public class SendMail
{
/**
* send multiple mails
* @param to1
* @param subject
* @param constent
* @exception Exception
*/
public static void sendItTo(Vector to1,String subject,String constent)
{
String from = "your email"
String host = "host";//例如“smtp.sina.com.cn”
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null);
session.setDebug(true); try
{
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress address[] = new InternetAddress[to1.size()]; for(int i=0;i<to1.size();i++){
address[i]=new InternetAddress((String)to1.elementAt(i));
} msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(constent); Transport.send(msg);
}
catch (Exception mex) {
mex.printStackTrace();
}
} /**
* send mail
* @param to1
* @param subject
* @param content1
* @exception Exception
*/
public static void sendItTo(String to1,String subject,String content1)
{
String to = to1;
String from = "your email"
String host = "host";//例如“smtp.sina.com.cn”
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null);
session.setDebug(true); try
{
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to1)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(content1); Transport.send(msg);
}
catch (Exception mex)
{
}
} public static void main(String args[])throws Exception
{
Vector vct = new Vector();
vct.addElement("email that will sent to ");
vct.addElement("[email protected]");
vct.addElement("[email protected]"); SendMail ss = new SendMail();
ss.sendItTo(vct,"hi","your mail"); }
}
import java.io.*;import javax.mail.*;
import javax.mail.internet.*;import javax.activation.*;public class SendMail
{
/**
* send multiple mails
* @param to1
* @param subject
* @param constent
* @exception Exception
*/
public static void sendItTo(Vector to1,String subject,String constent)
{
String from = "your email"
String host = "host";//例如“smtp.sina.com.cn”
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null);
session.setDebug(true); try
{
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress address[] = new InternetAddress[to1.size()]; for(int i=0;i<to1.size();i++){
address[i]=new InternetAddress((String)to1.elementAt(i));
} msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(constent); Transport.send(msg);
}
catch (Exception mex) {
mex.printStackTrace();
}
} /**
* send mail
* @param to1
* @param subject
* @param content1
* @exception Exception
*/
public static void sendItTo(String to1,String subject,String content1)
{
String to = to1;
String from = "your email"
String host = "host";//例如“smtp.sina.com.cn”
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null);
session.setDebug(true); try
{
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to1)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(content1); Transport.send(msg);
}
catch (Exception mex)
{
}
} public static void main(String args[])throws Exception
{
Vector vct = new Vector();
vct.addElement("email that will sent to ");
vct.addElement("[email protected]");
vct.addElement("[email protected]"); SendMail ss = new SendMail();
ss.sendItTo(vct,"hi","your mail"); }
}
用這些就要先下載javamail api(java.sun.com),或者下載j2ee
你自己写个网络邮件协议就可以解决问题了。
不用邮件服务器和web邮局放在一起,那只有用application收发。