【发布时间】:2009-12-22 10:22:58
【问题描述】:
我目前正在编写一段代码,需要在 它生成的电子邮件。附件是 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
【问题讨论】:
-
那是实际的代码吗?你在哪里填充内存流?
标签: .net vb.net email memorystream