2011-12-09 3 views
3

내 Lotus Notes 전자 메일을 하드 드라이브로 내보내 (저장)해야합니다. 첨부 파일을 HDD에 저장하는 방법을 알아 냈지만 전체 전자 메일을 저장하는 방법을 이해할 수는 없습니다.Lotus Notes - 전체 전자 메일 메시지 저장 eml C#

아래 코드는 첨부 파일을 내보내는 방법을 보여줍니다. 이메일을 저장하기 위해 어떻게 수정할 수 있습니까? PS- 프로그래밍 초보자입니다. Bob Babalan에 의해

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Domino; 
using System.Collections; 

namespace ExportLotusAttachments 
{ 
    class Class1 
    { 
    public void ScanForEmails() 
    { 
     String textBox1 = "c:\\1"; 
     NotesSession session = new NotesSession(); 
     session.Initialize(""); 
     NotesDbDirectory dir = null; 
     dir = session.GetDbDirectory(""); 
     NotesDatabase db = null; 
     db = dir.OpenMailDatabase(); 
     NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection 

     //ArrayList that will hold names of the folders 
     ArrayList LotusViews2 = new ArrayList(); 

     foreach (NotesView V in NDb.Views) 
     { 
     if (V.IsFolder && !(V.Name.Equals("($All)"))) 
     { 
      NotesView getS = V; 
      LotusViews2.Add(getS.Name); 
     } 
     } 

     foreach (String obj in LotusViews2) 
     { 
     NotesDocument NDoc; 
     NotesView nInboxDocs = NDb.GetView(obj); 
     NDoc = nInboxDocs.GetFirstDocument(); 
     String pAttachment; 

     while (NDoc != null) 
     { 
      if (NDoc.HasEmbedded && NDoc.HasItem("$File")) 
      { 
      object[] AllDocItems = (object[])NDoc.Items; 
      foreach (object CurItem in AllDocItems) 
      { 
       NotesItem nItem = (NotesItem)CurItem; 
       if (IT_TYPE.ATTACHMENT == nItem.type) 
       { 
       String path = textBox1; 
       pAttachment = ((object[])nItem.Values)[0].ToString(); 

       if (!System.IO.Directory.Exists(path)) 
       { 
        System.IO.Directory.CreateDirectory(textBox1); 
       } 

       try 
       { 
        NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment); 
       } 
       catch { } 
       } 
      } 
      } 
      NDoc = nInboxDocs.GetNextDocument(NDoc); 
     } 
     } 
    } 
    } 
} 
+0

게시하기 전에 서식을 지정하기 위해 코드를 미리 보시기 바랍니다. 입력 한 영역 아래를 보면이 코드를 미리 볼 수 있습니다. 그것은 당신의 질문을 더 가독하게 만들뿐만 아니라, 다른 사람들이 그것을 고쳐야하기 때문에 시간을 절약 할 수 있습니다. :) 사람들이 읽고 이해하는 것이 더 쉬울수록 더 많은 대답을 얻을 수 있습니다. 감사. –

답변

3

This 포스트는 자바를 사용 연꽃 문서를 내보낼 방법을 설명합니다. 동일한 원칙이 C#이나 VB에서 작동해야합니다. 문서가 MIME으로 변환되어 디스크에 기록됩니다.

또는 버전 8.5.3 (필자는 8.5.1 버전부터 시작했다)에서 메일 파일에서 파일 시스템으로 드래그 앤 드롭 만하면됩니다.

+1

불행히도 .eml 기능으로 드래그 앤 드롭이 API를 통해 노출되지 않습니다. – leyrer

+0

그래서 전자 메일을 가져 와서 HDD에 저장하는 방법은 전혀 없습니다. – Andrew

+0

물론 있지만, 위에서 설명한대로 프로그래밍이 필요할 수도 있습니다. 결과는 이메일과 함께 html 파일이됩니다. –

0

나는 조금 늦었다 고 알고있다. 그러나 이것은 내가 한 일이다. (Bob Babalan 기준) Bobs Solution은 NotesMIMEEntities를 이해하는 데 많은 도움이되었지만 해결책으로는 MIME-Tree를 두 번째 "계층"으로 트래버스했습니다. 이렇게하면 여러 레이어가 이동합니다.

public void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity) 
{ 
    try 
    { 
     string contentType = null; 
     string headers = null; 
     string content = null; 
     string preamble = null; 
     MIME_ENCODING encoding; 

     contentType = mimeEntity.ContentType; 
     headers = mimeEntity.Headers; 
     encoding = mimeEntity.Encoding; 

     // message envelope. If no MIME-Version header, add one 
     if (!headers.Contains("MIME-Version:")) 
      writer.WriteLine("MIME-Version: 1.0"); 
     writer.WriteLine(headers); 

     // for multipart, usually no main-msg content... 
     content = mimeEntity.ContentAsText; 
     if (content != null && content.Trim().Length > 0) 
      writer.WriteLine(content); 
     writer.Flush(); 

     if (contentType.StartsWith("multipart")) 
     { 
      preamble = mimeEntity.Preamble; 
      NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity(); 

      while (mimeChild != null) 
      { 
       GetMimeChild(writer, mimeChild); 
       mimeChild = mimeChild.GetNextSibling(); 
      } 
     } 

     writer.WriteLine(mimeEntity.BoundaryEnd); 
     writer.Flush(); 
    } 
    catch (Exception ex) 
    { 
     Logging.Log(ex.ToString()); 
    } 
} 

private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity) 
{ 
    string contentType = null; 
    string headers = null; 
    string content = null; 
    string preamble = null; 
    MIME_ENCODING encoding; 

    contentType = mimeEntity.ContentType; 
    headers = mimeEntity.Headers; 
    encoding = mimeEntity.Encoding; 

    if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY) 
    { 
     mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64); 
     headers = mimeEntity.Headers; 
    } 

    preamble = mimeEntity.Preamble; 
    writer.Write(mimeEntity.BoundaryStart); 

    if (!content.EndsWith("\n")) 
     writer.WriteLine(""); 

    writer.WriteLine(headers); 
    writer.WriteLine(); 

    writer.Write(mimeEntity.ContentAsText); 

    if (contentType.StartsWith("multipart")) 
    { 
     preamble = mimeEntity.Preamble; 
     NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity(); 

     while (mimeChild != null) 
     { 
      GetMimeChild(writer, mimeChild); 
      mimeChild = mimeChild.GetNextSibling(); 
     } 
    } 

    writer.Write(mimeEntity.BoundaryEnd); 
    writer.Flush(); 
} 

이 방법을 사용하여 EML 파일을 지정된 경로에 저장합니다.

using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None)) 
{ 
    using (StreamWriter writer = new StreamWriter(fs)) 
    { 
    NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity(); 
    if (mimeEntity != null) 
     email.GetMIME(writer, mimeEntity); 
    } 
} 
관련 문제