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");    }
}

解决方案 »

  1.   

    一般用smtp,pop3,imap4.
    用這些就要先下載javamail api(java.sun.com),或者下載j2ee
      

  2.   

    用这些?那样岂不是将web页面放在另外一部远程计算机都行了???
      

  3.   

    用jsp訪問mail服務器,沒有辦法不通過這些服務,除非mail服務器是你自己寫的,比如用Exchange Server,你能用其它的方式嗎?
      

  4.   

    不知道有幾個網站是用jsp做mail的,有的話,肯定不是用這種方式(太慢,因這些服務是用於Internet傳輸郵件的,不是用于局域網),而是連郵件服務器一起做的.
      

  5.   

    能说一下原理吗??不用smtp、pop3,邮件服务器和web邮局放在一起,用什么方式接收和发送邮件?
      

  6.   

    不用smtp、pop3,起?
    你自己写个网络邮件协议就可以解决问题了。
    不用邮件服务器和web邮局放在一起,那只有用application收发。
      

  7.   

    不不,邮件服务器和web邮局是放在一起的,我想知道一下原理,谁能给我说说,介绍一下也好啊
      

  8.   

    郵件服務器和web放在一起的話,如用Exchange,我不知道有甚麼方法可以直接訪問它的數據,一般郵件服務器的數據出於安全性考慮,是不允許直接訪問它的數據的,只有通過它提供的接口或服務來訪問,除非郵件服務器或郵件協議是自己開發的.