没有做过,不敢说,是不是你相关的jar文件没有包含进去?

解决方案 »

  1.   

    呵呵,个人没做过javamail!
    帮你up
      

  2.   

    是不是打包的时候哪个类没有打进去?你打包的时候所有的Library都是选的 Always include all classes and resources么?如果不是你把所有的Library都选成它打包试试。我以前打包一个程序时也出现过这种问题,我想把包打小一点,所以选了required,但是打出来不能运行,后来选择all,就可以运行了。
      

  3.   

    UP。
    是不是有某些资源,如图片等,不能打进exe里,要放在与exe文件同一个目录下。
      

  4.   

    因为JB中有许多自己开发的CLASS,所以会出现这些问题!
    而且你出现的是某种数据类型不被JAVA识别!所以你还是贴出代码,才好解决
      

  5.   

    package listingwapjf;import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.mail.internet.MimePart.*;
    import javax.activation.DataContentHandler;
    import javax.activation.CommandMap;
    import javax.activation.DataHandler;public class sendmail extends Thread {
      private Message mimeMsg; //MIME郵件物件
      private Session session; //郵件會話物件
      private Properties props; //系统属性
      private boolean needAuth=true; //smtp是否需要認證
      private String username="[email protected]"; //smtp用户名
      private String password="1234";//smtp密码
      private String hostName="mail.banruo.net";
      private Multipart mp; //Multipart物件,郵件內容,標題,附件等內容均添加到其中後再生成MimeMessage物件
      private String mailSubject="";//主题
      private String mailBody;//内容
      private String tomailaddress_TO="";//发送给
      private String tomailaddress_CC="";//发送给
      private String frommailaddress="[email protected]";//发送者
      public sendmail(String mailSubject_tmp,String mailBody_tmp) {
        mailSubject=mailSubject_tmp;
        mailBody=mailBody_tmp;
        props=System.getProperties();
        props.put("mail.smtp.host",hostName); //设置SMTP主机地址
        if(needAuth)
        {
          props.put("mail.smtp.auth","true");
        }
        else
        {
          props.put("mail.smtp.auth","false");
        }
      }
      public synchronized void run() {
           if(public_var.emaillist.size()==0)
           {//没有邮件地址
             return;
           }
           for(int i=0;i<public_var.emaillist.size();i++)
           {
              if(i==0)
              {
                tomailaddress_TO=(String)public_var.emaillist.get(i);//主邮件地址
              }
              else
              {
                if(i+1==public_var.emaillist.size())
                {
                  tomailaddress_CC=tomailaddress_CC+(String)public_var.emaillist.get(i);//主邮件地址
                }
                else
                {
                  tomailaddress_CC=tomailaddress_CC+(String)public_var.emaillist.get(i)+",";//主邮件地址
                }
              }
           }
          //---------------//创建MIME邮件 begin
          try{
             session = Session.getDefaultInstance(props,null);
             session.setDebug(true);
          }
          catch(Exception e){
            System.err.println("zhengqiang0");
            System.out.println(e.getMessage());
            return;
          }
          try{
             mimeMsg = new MimeMessage(session);
             mp = new MimeMultipart();
          }
          catch(Exception e){
            System.err.println("zhengqiang1");
            System.out.println(e.getMessage());
            return;
          }
          //---------------//创建MIME邮件 end
          //---------------设置邮件主题 begin
          try{
          mimeMsg.setSubject(mailSubject);
          }
          catch(Exception e) {
            System.err.println("zhengqiang2");
            System.out.println(e.getMessage());
            return;
          }
          //---------------设置邮件主题 end
          //----------------设置邮件正文 begin
          try{
           //BodyPart bp = new MimeBodyPart();
          //bp.setContent("<meta http-equiv=Content-Type content=text/html; charset=GB2312>"+mailBody,"text/html; charset=GB2312");
          //bp.setContent(mailBody,"text/html; charset=gb2312");
          //mp.addBodyPart(bp);
           //----------
            CommandMap cmp=CommandMap.getDefaultCommandMap();
            DataContentHandler DCH = cmp.createDataContentHandler("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");//contenttype="text/palin",,"multipart/*"...
            if(DCH==null)
            {
             // throw new UnSupprotedDataTypeException("no object DCH for MIME type"+contenttype);
             System.out.println("zhengqiang");
            }
            //----------
           mimeMsg.addHeader("Content-Type","text/html");
           //mimeMsg.
           String htmlText="<H1>Hello</H1>"+"<img src=\"http://www.jguru.com/images/logo.gif\">";
           mimeMsg.setContent(htmlText,"text/html");
    //       mimeMsg.setDataHandler(new DataHandler(javax.mail.Header.g,"text/plain"));
          }
          catch(Exception e){
            System.err.println("zhengqiang3");
            System.out.println(e.getMessage());
            return;
          }
          //----------------设置邮件正文 end
          //----------------设置发送日期 begin
           try{
                mimeMsg.setSentDate(new Date());
              }
              catch(Exception e)
              {
                System.err.println("zhengqiang4");
                System.out.println(e.getMessage());
                return;
              }
          //----------------设置发送日期 end
          //----------------设置发送给谁 begin
          try{
          mimeMsg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(tomailaddress_TO));
          mimeMsg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(tomailaddress_CC));
          }
          catch(Exception e)
          {
            System.err.println("zhengqiang5");
            System.out.println(e.getMessage());
            return;
          }
          //----------------设置发送给谁 end
          //----------------设置发送者 begin
            try{
            mimeMsg.setFrom(new InternetAddress(frommailaddress));
            }
            catch(Exception e)
            {
             System.err.println("zhengqiang6");
             return;
            }
           //----------------设置发送者 end
           //----------------开始发送 begin
            try{
            System.out.println("tttttttttttttttt0");
    //        mimeMsg.setContent(mp);
            System.out.println("tttttttttttttttt1");
    //        mimeMsg.saveChanges();
            System.out.println("tttttttttttttttt2");
            Session mailSession = Session.getInstance(props,null);
            System.out.println("tttttttttttttttt3");
            Transport transport = mailSession.getTransport("smtp");
            System.out.println("tttttttttttttttt4");
            transport.connect((String)props.get("mail.smtp.host"),username,password);
             System.out.println("tttttttttttttttt5");
            //transport.send(mimeMsg);
            transport.sendMessage(mimeMsg,mimeMsg.getRecipients(Message.RecipientType.TO));
              System.out.println("tttttttttttttttt6");
            //transport.send(mimeMsg,mimeMsg.getRecipients(Message.RecipientType.CC));
            //transport.sendMessage(mimeMsg,mimeMsg.getRecipients(Message.RecipientType.CC));
              System.out.println("tttttttttttttttt7");
            transport.close();
            }
            catch(Exception e)
            {
              System.err.println("zhengqiang7");
              System.err.println(e.getMessage());
              return;
            }
           //----------------开始发送 end
          return;
        //-----------
      }
    }说明:
    transport.sendMessage(mimeMsg,mimeMsg.getRecipients(Message.RecipientType.TO));
    这句话就出错了!
      

  6.   

    以上是java application的程序
      

  7.   

    我的问题与这个问题比较像,但是我没有看懂它的解决方法!
    http://search.csdn.net/expert/topic/54/5404/2003/11/27/2500375.xml
      

  8.   

    经过偶多方测试,终于找到解决方法  :)在sendmail.exe的同级文件夹下建一目录META-INF,在这个目录里再新建一个问叫mailcap,mailcap内容如下#
    # @(#)mailcap 1.6 02/05/23
    #
    # Default mailcap file for the JavaMail System.
    #
    # JavaMail content-handlers:
    #
    text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain
    text/html;; x-java-content-handler=com.sun.mail.handlers.text_html
    text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml
    image/gif;; x-java-content-handler=com.sun.mail.handlers.image_gif
    image/jpeg;; x-java-content-handler=com.sun.mail.handlers.image_jpeg
    multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed
    message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822