2014-07-25 3 views
0

SQL 데이터베이스에서 데이터를 가져 오는 IMAP 서버를 설정하려고합니다. 메시지에 아무런 문제가 없지만 첨부 파일을 첨부하는 방법을 알아낼 수 없습니다.Lumisoft.net IMAP 서버가 메시지에 첨부 파일을 추가 할 수 없습니다.

Mail_Message 개체의 첨부 개체에는 getter와 GetAttachments()라는 메서드가 있으며 어디에도 연결되어 있지 않습니다.

내 현재 코드입니다 : 뭔가 누락하거나이 잘못 설정 가지고있어 경우

//this is my own object I'm using to pull data from the database 
var cmMsg = _ml.GetMessage(mId, session.AuthenticatedUserIdentity.Name, -1); 

var msgBody = new MIME_b_Text(MIME_MediaTypes.Text.html); 
var msg = new Mail_Message(); 
msg.Body = msgBody; 
msg.To = new Mail_t_AddressList(); 
msg.From = new Mail_t_MailboxList {new Mail_t_Mailbox(cmMsg.From, cmMsg.FromEmail)}; 
msg.Cc = new Mail_t_AddressList(); 
msg.Bcc = new Mail_t_AddressList(); 

foreach (var recipient in cmMsg.Recipients) 
{ 
    if (recipient.isTo) 
    { 
     msg.To.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
    } 
    else if(recipient.isCC) 
    { 
     msg.Cc.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
    } 
    else if (recipient.isBCC) 
    { 
     msg.Bcc.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
    } 
} 

//I tried adding a setter to the attachment object, but just get errors with this code 
var a = new List<MIME_Entity>(); 

foreach (var attachment in cmMsg.Attachments) 
{ 
    var aCT = new MIME_b_Multipart(new MIME_h_ContentType("application/octet-stream")); 


    a.Add(new MIME_Entity 
    { 
     Body = aCT, 
     ContentDisposition = new MIME_h_ContentDisposition("attachment"), 

    }); 
} 
msg.Attachments = a.ToArray(); 

msg.Subject = cmMsg.Subject; 
msg.Date = cmMsg.TimeDate; 
msg.MessageID = cmMsg.InternetMessageId; 

if (e.FetchDataType == IMAP_Fetch_DataType.MessageStructure) 
{ 

} 
else if(e.FetchDataType == IMAP_Fetch_DataType.MessageHeader) 
{ 

} 
else 
{ 
    msgBody.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, cmMsg.HtmlBody); 
    _da.MarkAsRead(archiveID, session.AuthenticatedUserIdentity.Name); 
} 

e.AddData(info, msg); 

잘 모르겠어요. 예제 프로젝트에 MySQL API가 있다는 것을 알았지 만 그 안에 첨부 파일과 관련이 없다.

답변

0

좋아, 그럼 내가 완전히 잘못된 방향으로 가고있는 것으로 나타났습니다. 아래 코드는 필수입니다.

효과적으로 메시지를 텍스트 대신 멀티 파트 믹스로 설정해야합니다. 그런 다음 첨부 파일을 본문 부분으로 추가 할 수 있습니다.

var cmMsg = _ml.GetMessage(mId, session.AuthenticatedUserIdentity.Name, -1); 

      MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed); 
      contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.'); 
      MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed); 
      var msg = new Mail_Message(); 
      msg.To = new Mail_t_AddressList(); 
      msg.From = new Mail_t_MailboxList {new Mail_t_Mailbox(cmMsg.From, cmMsg.FromEmail)}; 
      msg.Cc = new Mail_t_AddressList(); 
      msg.Bcc = new Mail_t_AddressList(); 
      msg.Body = multipartMixed; 

      foreach (var recipient in cmMsg.Recipients) 
      { 
       if (recipient.isTo) 
       { 
        msg.To.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
       } 
       else if(recipient.isCC) 
       { 
        msg.Cc.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
       } 
       else if (recipient.isBCC) 
       { 
        msg.Bcc.Add(new Mail_t_Mailbox(recipient.FullName, recipient.SMTPAddress)); 
       } 
      } 

      msg.Subject = cmMsg.Subject; 
      msg.Date = cmMsg.TimeDate; 
      msg.MessageID = cmMsg.InternetMessageId; 
      msg.MimeVersion = "1.0"; 
      msg.Header.Add(new MIME_h_Unstructured("X-MS-Has-Attach", "yes")); 

      if (e.FetchDataType == IMAP_Fetch_DataType.MessageStructure) 
      { 

      } 
      else if(e.FetchDataType == IMAP_Fetch_DataType.MessageHeader) 
      { 

      } 
      else 
      { 
       MIME_Entity entity_text_plain = new MIME_Entity(); 
       MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain); 
       entity_text_plain.Body = text_plain; 
       text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, cmMsg.HtmlBody); 
       multipartMixed.BodyParts.Add(entity_text_plain); 


       foreach (var attachment in cmMsg.Attachments) 
       { 
        using (var fs = new FileStream(@"C:\test.txt", FileMode.Open)) 
        { 
         multipartMixed.BodyParts.Add(Mail_Message.CreateAttachment(fs, "test.txt")); 
        } 
       } 
      } 

      e.AddData(info, msg); 
관련 문제