2015-01-30 2 views
0

S22.imap 라이브러리를 사용하여 사서함에서 모든 전자 메일을 다운로드하고 있습니다. 일부 메시지에는 첨부 파일이 있습니다. 첨부 파일이있는 일부 전자 메일을 전달하거나 전자 메일 양식의 첨부 파일이있는 새 전자 메일을 만들려합니다.S22.Imap 첨부 파일 가져 오기

문제는 첨부 파일을 가져 와서 내 첨부 파일로 추가 할 수 없다는 것입니다.

그래서 기본적으로 : MailMessage 개체가 있고 첨부 된 파일을 가져 와서 새 MailMessage 개체에 추가하려고합니다.

+0

[C#을 정지 게으름과 자신의 물건 .COM 코딩 시작] 포럼 사이트와 달리, 우리는 "감사합니다"를 사용하지 않는 – MethodMan

+0

을 (http://www.google.com), 또는 "어떤 도움에 감사드립니다 "또는 서명 [so]. "[안녕하세요, '고마워,'태그 라인 및 인사말을 게시물에서 삭제해야합니까?] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be 참조) -removed-from-posts). –

답변

1

누구나 같은 문제가있는 경우 : MailMessage 객체를 통해 반복합니다. foreach (message.Attachments의 첨부 파일 첨부) 및 stream attachment.ContentStream을 스트림합니다. 그런 다음 새 메시지에 스트림을 추가하십시오.

2
foreach (Attachment attachment in message.Attachments) 
{ 
    byte[] allBytes = new byte[attachment.ContentStream.Length]; 
    int bytesRead = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length); 
    string destinationFile = @"C:\\Path\\" + attachment.Name; 
    BinaryWriter writer = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)); 
    writer.Write(allBytes); 
    writer.Close(); 
} 
관련 문제