1

私は現在、生成された電子メールに添付ファイルを送信する必要があるコードを作成しています。添付ファイルは PDF ドキュメントです。要件により、PDF を保存して送信することができないため、メモリ ストリームの添付ファイルを作成する必要がありました。

これに関する問題は、ファイル サイズが _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
4

2 に答える 2

4

問題は、添付ファイルを Base64 でエンコードする必要があることです。未加工のバイナリ データは電子メールでは「存続」しないため、特定の「安全な」文字のみを使用する形式にエンコードする必要があります。これにより、サイズが増加します。生のバイナリには256の「文字」がありますが、Base64エンコーディングには64しかありません。実際にはそれを回避する方法はありません。

于 2009-12-22T10:25:28.533 に答える
2

この増加は、電子メールに添付される際のバイナリ データの base64 エンコーディングが原因であると考えられます。私の知る限り、これについてあなたができることは何もありません。

于 2009-12-22T10:25:40.163 に答える