Java代理实现domino web邮件下载

近日在研究domino web邮件下载功能,下载的邮件可以导入foxmail、outlook邮件客户端,下载的邮件格式为eml。

【参考代码】(需要下载jmail.jar包)

jar包下载地址:jar包下载

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是

具体下载目录在 /2014年资料/7月/24日/Java代理实现domino web邮件下载

下载方法见

------------------------------------------分割线------------------------------------------

private void makeEml(String unid) {
  Document memo=null;
  RichTextItem body=null;
  try {   
   memo = maildb.getDocumentByUNID(unid);
   String mailtime=((String) memo.getCreated().getLocalTime());
   String d_email = memo.getItemValueString("From");
   Vector v_to = memo.getItemValue("SendTo");   
   Vector v_cc = memo.getItemValue("CopyTo");
   Vector v_bcc = memo.getItemValue("BlindCopyTo");
     
   String m_subject = memo.getItemValueString("Subject");
   String m_text = memo.getItemValueString("Body");

Properties props = new Properties();
   Session session = Session.getInstance(props, null);

//System.out.println("-----00000000------");
   try {   
    MimeMessage msg = new MimeMessage(session);
    msg.setSubject(m_subject);
   
    //msg.setFrom(new InternetAddress(javax.mail.internet.MimeUtility.encodeText(d_email,"UTF-8", "B").replaceAll(" ", "")));

msg.setFrom(new InternetAddress(javax.mail.internet.MimeUtility.encodeText((String)d_email,"UTF-8", "B").replaceAll(" ", "")));

//System.out.println("-----111111------");
    for (int i=0; i<v_to.size(); i++){
     System.out.println("-----111111---0000---="+javax.mail.internet.MimeUtility.encodeText((String) v_to.elementAt(i),"UTF-8", "B").replaceAll(" ", ""));
     InternetAddress[] toaddress = InternetAddress.parse(javax.mail.internet.MimeUtility.encodeText((String) v_to.elementAt(i),"UTF-8", "B").replaceAll(" ", ""));
                       
     msg.addRecipients(Message.RecipientType.TO, toaddress);
     //msg.addRecipients(Message.RecipientType.TO, toaddress);
     //System.out.println("-----111111---1111--222-");
    }   
    for (int i=0; i<v_cc.size(); i++){
     InternetAddress[] ccaddress = InternetAddress.parse(javax.mail.internet.MimeUtility.encodeText((String) v_cc.elementAt(i),"UTF-8", "B").replaceAll(" ", ""));
     msg.addRecipients(Message.RecipientType.CC, ccaddress);
    } 

//System.out.println("-----111111--333----");
    for (int i=0; i<v_bcc.size(); i++){
     InternetAddress[] bccaddress = InternetAddress.parse(javax.mail.internet.MimeUtility.encodeText((String) v_bcc.elementAt(i),"UTF-8", "B").replaceAll(" ", ""));
     msg.addRecipients(Message.RecipientType.BCC, bccaddress);
    }   

MimeBodyPart p1 = new MimeBodyPart();
    p1.setText(m_text);

Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);

String extractMimePath=extractPath+memo.getNoteID()+"/";
    File extractDir2 = new File(extractMimePath);
    extractDir2.mkdirs();

MIMEEntity mime = memo.getMIMEEntity();
   
    if (mime != null) {   
     MimeBodyPart p2 = new MimeBodyPart(mime.getInputStream());
     mp.addBodyPart(p2);
    } else {
                        //System.out.println("Body="+m_text);
                        //System.out.println("Body="+memo.getFirstItem("Body").getType())
        body = (RichTextItem) memo.getFirstItem("Body");
     Vector v = body.getEmbeddedObjects();
     Enumeration e = v.elements();
     while (e.hasMoreElements()) {
      eo = (EmbeddedObject) e.nextElement();
      filename = eo.getName();     
      eo.extractFile(extractMimePath + filename);
      FileDataSource fds = new FileDataSource(extractMimePath
        + filename);     
      MimeBodyPart p2 = new MimeBodyPart();
      p2.setDataHandler(new DataHandler(fds));
      p2.setHeader("Content-Transfer-Encoding", "Base64"); 
      p2.setFileName(MimeUtility.encodeText(filename));
      mp.addBodyPart(p2);
     }     
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/90f7ae2bcf189907a2f50dec6f520b75.html