I am currently working a piece of code which needs to send an attachment in the email it generates. The attachment is a PDF document. Due to requirements I am unable to save the PDF and send it, so I have had to create a memory stream attachment.
The issue I have with this is that the file size is _500KB. However save the file on my machine and it is around 370KB.
This increase in file size is unacceptable. has anyone come across this issue before? If so how have they got round the problem.
Below is the section of code. '
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