2013-04-12 2 views
0

Outlook 상자에서 내 모든 메시지를 복구해야합니다. OpenPop 오픈 소스를 사용하지만 일반 텍스트 (값이 널입니다)를 복구 할 수없고 메일을 확인할 때 일반 텍스트가 있기 때문에 이해가되지 않습니다. 내가 HTML 버전을 시도 할 때 작동하지만이 프로젝트는 필요하지 않습니다. 나를 도울 수있는 사람 덕분에.OpenPop.Mime은 일반 텍스트를 찾지 못합니다

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Data.SqlClient; 
using System.Globalization; 
using System.IO; 
using System.Net.Security; 
using System.Net.Sockets; 
using System.Text; 
using System.Windows.Forms; 
using OpenPop.Mime; 
using OpenPop.Pop3; 

namespace EmailGmail 
{ 
    public partial class WebForm1 : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      string hostname = ***; 
      int port = **; 
      bool useSsl = true; 
      string username = ***; 
      string password = ***; 

      List<OpenPop.Mime.Message> allaEmail = FetchAllMessages(hostname, port, useSsl, username, password); 

      foreach (OpenPop.Mime.Message message in allaEmail) 
      { 
       OpenPop.Mime.MessagePart plainText = message.FindFirstPlainTextVersion(); 

       OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion(); 

      } 
     } 

     public static List<OpenPop.Mime.Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password) 
     { 

      // The client disconnects from the server when being disposed 
      using (Pop3Client client = new Pop3Client()) 
      { 
       try 
       { 

       // Connect to the server 
       client.Connect(hostname, port, useSsl); 

       // Authenticate ourselves towards the server 
       client.Authenticate(username, password); 

       // Get the number of messages in the inbox 
       int messageCount = client.GetMessageCount(); 

       // We want to download all messages 
       List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount); 

       // Messages are numbered in the interval: [1, messageCount] 
       // Ergo: message numbers are 1-based. 
       // Most servers give the latest message the highest number 
       for (int i = messageCount; i > 0; i--) 
       { 
        allMessages.Add(client.GetMessage(i)); 
       } 

       // Now return the fetched messages 
       return allMessages; 
       } 
       catch (Exception ex) 
       { 
        return null; 
       } 

      } 

     } 
    } 
} 

답변

1

나는 동일한 문제가있었습니다. 본문의 원시 데이터를 선택하고 바이트를 읽을 수있는 텍스트 (문자열)로 변환하는 방법을 사용하여 해결했습니다.

string Body = msgList[0].MessagePart.MessageParts[0].GetBodyAsText(); 

다음은 본문 텍스트입니다.

msgList는 일련의 메시지를 제공하는 FetchAllMe 메시지를 호출 한 결과입니다. 모든 메시지에는 본문 텍스트가 포함 된 MessagePart가 있습니다. GetBodyAsText를 사용하여 본문 텍스트를 검색하십시오. GetBodyAsText는 OpenPop 라이브러리에 이미 포함되어 있으므로 내 방법이 아닙니다.

희망 사항은 의심의 여지가 없기를 바랍니다.

1
private void button7_Click(object sender, EventArgs e) 
{ 
    List<OpenPop.Mime.Message> allaEmail = FetchAllMessages(...); 

    StringBuilder builder = new StringBuilder(); 
    foreach(OpenPop.Mime.Message message in allaEmail) 
    { 
     OpenPop.Mime.MessagePart plainText = message.FindFirstPlainTextVersion(); 
     if(plainText != null) 
     { 
      // We found some plaintext! 
      builder.Append(plainText.GetBodyAsText()); 
     } else 
     { 
      // Might include a part holding html instead 
      OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion(); 
      if(html != null) 
      { 
       // We found some html! 
       builder.Append(html.GetBodyAsText()); 
      } 
     } 
    } 
    MessageBox.Show(builder.ToString()); 
} 
+0

메일을 HTML 형식으로 가져 오는 경우 값을 저장 한 다음 다른 메일 (gmail, outlook, yahoo)의 표준 형식을 찾습니다. { 시작 = messageBody.ToLower() 같이 IndexOf이 ("전송") : 야후 보낸 메시지 검색의 경우 (.) "전송"(포함) messageBody.ToLower() 경우 .. 사용할 수 있습니다.; end = 시작 +100; } –

관련 문제