私は現在、生成された電子メールに添付ファイルを送信する必要があるコードを作成しています。添付ファイルは 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