2009-12-22 2 views
1

현재 생성 된 전자 메일의 첨부 파일을 보내야하는 코드를 작업하고 있습니다. 첨부 파일은 PDF 문서입니다. 요구 사항으로 인해 은 PDF를 저장하고 보낼 수 없으므로 메모리 스트림 첨부 파일을 만들어야했습니다.전자 메일 첨부 파일을 보내면 .net의 첨부 파일 크기가 늘어납니다.

내가 가진이 문제점은 파일 크기가 _500KB라는 것입니다. 그러나 내 컴퓨터에 파일을 저장하면 약 370KB입니다.

이러한 파일 크기의 증가는 용납되지 않습니다. 누구든지 전에이 문제를 보았습니까? 그렇다면 어떻게 문제를 해결할 수 있었습니까?

다음은 코드 섹션입니다. '

Dim memStream As System.IO.MemoryStream = Nothing 
'assign number to the PDF name 
Dim filename As String = req.GetAccountNumber() 
'add file extension 
filename &= ".pdf" 

'initialise the memory stream 
memStream = New System.IO.MemoryStream() 

'generate the pdf and put it in a byte array 
Dim arrBytData() As Byte = CType(PDFRequest(),Byte())) 

'flush the stream 
memStream.Flush() 

'Create new instances of the message and attachments 
'and intialise them 
Dim msg As New System.Net.Mail.MailMessage(req.EmailFrom, req.EmailTo) 
Dim att As New System.Net.Mail.Attachment(memStream, filename) 

With msg 
    .Attachments.Add(att) 
    .Body = req.EmailBody 
    .Subject = req.EmailSubject 
End With 

'connect to the server and send the message 
Dim client As New System.Net.Mail.SmtpClient() 
client.Host = PDFService(Of T).mSMTPServer 
client.Send(msg) 

'Close our stream 
memStream.Close() 
msg = Nothing 
+0

은 실제 코드입니까? 메모리 스트림을 어디에서 채우고 있습니까? –

답변

4

문제는 첨부 전자 메일에 "생존"되지 Base64- 원시 이진 데이터로 부호화되어야한다는이므로은 "특정 사용하는 형태로 인코딩되어야 안전 "문자. Base64 인코딩에는 64 개가있는 반면, 원시 바이너리는 256 개의 "문자"를 가지며 크기는 커집니다.

+1

와우, 나는 그 대답에서 따옴표를 많이 사용했다. 죄송합니다. :) – nitzmahone

+0

괜찮아요, 제 브라우저에는 글리프가 가득 찼습니다.) – Niklas

+0

분명히 내가 원했던 대답은 아니지만 크기의 증가를 설명합니다. – Miker169

2

증가량은 전자 메일에 첨부 할 때 이진 데이터의 base64 인코딩 때문일 수 있습니다. AFAIK 여기에 대해 할 수있는 일이 없습니다.

관련 문제