Properties aProperties = System.getProperties();
        aProperties.put("mail.transport.protocol","smtp");
        aProperties.put("mail.smtp.host","smtp.xxx.com");
pros.put("mail.smtp.port", "8025");
        Session session = Session.getInstance(aProperties,null);        MimeMessage message = new MimeMessage(session);

解决方案 »

  1.   

    Properties aProperties = System.getProperties();
            aProperties.put("mail.transport.protocol","smtp");
            aProperties.put("mail.smtp.host","smtp.xxx.com");
            aProperties.put("mail.smtp.port", "9025");
            Session session = Session.getInstance(aProperties,null);        MimeMessage message = new MimeMessage(session);
      

  2.   

    //  经典代码----收邮件<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
    <%
    Properties props = new Properties();
    props.put("mail.smtp.host","192.168.199.3");
    Session s = Session.getInstance(props,null);// Store store = s.getStore("pop3");

    int port = 8110;
    String username = "yourname#pop.21cn.com";
    String password = "******";
    String server = "192.168.199.1";
    String protocol = "pop3";
    String file = "C:/home/mail/999/Maildir/rev";
    s.setDebug(false);
    URLName urln = new URLName(protocol,server,port,file,username,password);
    // URLName urln = new URLName(CONST.maildir,CONST.mailhost,8008,maildir,userid,passwd);
    Store store = s.getStore(urln);
    s.setDebug(true); //  true = s.getDebug()  有何实际意义???// URLName url = new URLName(protocol,getHostname(), -1, mbox,getUsername(),getPassword());
    // Properties props = System.getProperties();
    //  props.put("mail.smtp.host",getHostname());
    //  Session session =  Session.getDefaultInstance(props,null); 
    //  Store store = session.getStore(url);
    // store.connect(); try{
    // store.connect(server,port,username,password);
    store.connect();
    }catch(MessagingException e){
    throw new Exception("Cannot log on to server.Please verify the username and password.");
    }
    try{
    String mbox = "INBOX";
    Folder folder = store.getFolder(mbox);
    folder.open(Folder.READ_ONLY);

    Message[] messages = folder.getMessages();

    for(int i=0;i<messages.length;i++){
    InternetAddress[] from = (InternetAddress[])messages[i].getFrom();
    InternetAddress[] to = (InternetAddress[])messages[i].
             getRecipients(Message.RecipientType.TO);
    %>
    <p>To <%= to[0].getAddress() %>, from <%= from[0].getAddress() %>,
    subject <%= messages[i].getSubject() %> </p>
    <%
    }
    }catch(MessagingException e){
    throw new Exception("Cannot read message.Please verify your E-mail server has a valid inbox");
    }finally{
    store.close();
    }
    %>