将你7行改为session.getStore("pop3");试试

解决方案 »

  1.   

    还是有异常。
    javax.mail.NoSuchProviderException:
    No provider for pop3
    javax.mail.NoSuchProviderException: No provider for pop
            at javax.mail.Session.getProvider(Session.java:249)
            at javax.mail.Session.getStore(Session.java:323)
            at javax.mail.Session.getStore(Session.java:303)
            at com.neusoft.oa.pemail.SessionAndDb.ReceiveMail(SessionAndDb.java:124)
    ……
      

  2.   

    把store = session_receive.getStore("imap");的IMAP改成POP3 试试
      

  3.   

    如果是(JDK1.5 + TOMCAT5.0 + WIN2003Enidtion  环境下)  
    首先要下载javamail-1_3_3_01.zip的.zip包,然后在  
    控制面版-->系统-->高级-->环境变量-->系统变量-->classpath  
    添加相应的.jar路径,有mailapi.jar,smtp.jar,pop3.jar等等其实只要用到一个mail.jar就可以的
    或者你用的是J2ee开发环境的话只要把mail.jar加入系统的环境变量就可以了源码:
    -------------------------------------------------------------------------------------------
    index.jsp:
    <html>
    <head>
    <title>发送e-mail的表单</title>
    </head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <body bgcolor="#CFF1E1">
    <center><h2>
    写信
    </h2></center>
    <form action="sendmail.jsp" method="post">
    <table align="center"> 
      <tr> 
        <td> 
          收件人地址:<br><input name="to" size="30"> 
        </td> 
      </tr> 
      <tr> 
        <td> 
          主题:<br><input name="subject" size="60"> 
        </td> 
      </tr> 
      <tr> 
        <td> 
          <p>内容:<br>
            <textarea name="text" rows=8 cols=60></textarea>
          </p> 
        </td> 
      </tr> 
      <tr>
        <td>
           附件:<br>
           <input type="file" name="attachment" size="25">
        </td>
      </tr>
    </table> 
    <center><p><br>
      <input type="submit" value="发送">&nbsp&nbsp&nbsp&nbsp&nbsp;
      <input type="reset" value="重写"> 
    </p></center>  
    </form> 
    </body>
    </html>--------------------------------------------------------------------------
    sendmail.jsp
    <html>
    <head>
    <title>发送e-mail</title>
    </head>
    <%@ page contentType="text/html;charset=GB2312"%>
    <%@ page import="javax.mail.*,javax.mail.internet.*,javax.activation.*,java.util.*"%>
    <body bgcolor="#CFF1E1">
    <% 
     //获取用户信息参数和邮件主机名
     String host=(String)session.getAttribute("host"); 
     String user=(String)session.getAttribute("user"); 
     String password=(String)session.getAttribute("password");  try{ 
          //获得属性,并生成Session对象 
          Properties props=new Properties(); 
          Session sendsession; 
          Transport transport; 
          sendsession = Session.getInstance(props, null); 
          //向属性中写入SMTP服务器的地址
          props.put("mail.smtp.host", "smtp."+host);
          //设置SMTP服务器需要权限认证
          props.put("mail.smtp.auth","true");
          //设置输出调试信息
          sendsession.setDebug(true);
          //根据Session生成Message对象
          Message message = new MimeMessage(sendsession); 
          //设置发信人地址
          message.setFrom(new InternetAddress(user+"@"+host)); 
          //设置收信人地址
          message.setRecipient(Message.RecipientType.TO,new InternetAddress(request.getParameter("to"))); 
          //设置e-mail标题 
          message.setSubject(new String(request.getParameter("subject").getBytes("ISO8859_1"),"GBK"));
          //设置e-mail发送时间
          message.setSentDate(new Date()); 
          //设置e-mail内容
          message.setText(new String(request.getParameter("text").getBytes("ISO8859_1"),"GBK"));
          //获得attachment参数
          String attachment=new String(request.getParameter("attachment").getBytes("ISO8859_1"),"GBK");
    //如有附件
    if (!attachment.equals(""))
    {
        //建立第一部分:文本正文
        BodyPart messageBodyPart=new MimeBodyPart();
        messageBodyPart.setText(new String(request.getParameter("text").getBytes("ISO8859_1"),"GBK"));
        // 建立多个部分Multipart实例
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        // 建立第二部分:附件  
        messageBodyPart=new MimeBodyPart();
        // 获得附件
        DataSource source=new FileDataSource(attachment);
        //设置附件的数据处理器
        messageBodyPart.setDataHandler(new DataHandler(source));
        // 设置附件文件名
        messageBodyPart.setFileName(attachment);
        // 加入第二部分
        multipart.addBodyPart(messageBodyPart);    
             // 将多部分内容放到e-mail中
             message.setContent(multipart);
            }else{
                //如无附件,则按纯文本格式处理
        message.setText(new String(request.getParameter("text").getBytes("ISO8859_1"),"GBK"));  
            }        
          //保存对于e-mail的修改
          message.saveChanges();
          //根据Session生成Transport对象
          transport=sendsession.getTransport("smtp"); 
          //连接到SMTP服务器
          transport.connect("smtp."+host,user,password);
          //发送e-mail
          transport.sendMessage(message,message.getAllRecipients());
          //关闭Transport连接
          transport.close();
    %>
    <p>e-mail成功发送到<%=request.getParameter("to")%>!</p>
    <p>附件<%=attachment%>一并发送成功!</p>
    <% 
       }
       catch(MessagingException m) 
       { 
          out.println(m.toString()); 
       } 
    %> 
    <center><h3>
    <br><a href="listlogin.html">请返回</a> 
    </h3></center>
    </body>
    </html>   
      

  4.   

    下载了javamail-1_3_3_01.zip,使用其中的mail.jar,还是报错。这次的错误为:
    javax.mail.MessagingException: A3 BAD failed;
      nested exception is:
            com.sun.mail.iap.BadCommandException: A3 BAD failed
            at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2221)
            at com.sun.mail.imap.IMAPFolder.exists(IMAPFolder.java:409)
            at com.sun.mail.imap.IMAPFolder.checkExists(IMAPFolder.java:283)
            at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:876)
            at com.xxx.oa.pemail.SessionAndDb.ReceiveMail(SessionAndDb.java:137)所指向的137行为:inbox.open(Folder.READ_ONLY);使用的有件服务器为winwebmail
      

  5.   

    store.connect(imapHostIP, username, userpassword);
    应该改为这样的store.connect(imapHostIP,-1, username, userpassword);
    在connect函数中需要四个参数,一个是主机地址,一个是端口号(默认是-1),另外的是你登录用户名和登录密码。如果有问题你可以联系我,我也正在做邮件服务。我的QQ是89496823
    EMAIL:[email protected]