Free Support Forum -

Emailing a pdf stream as an attachment


I've created a pdf (using your aspose.pdf) in a memorystream (I'm not sure if you can do this?!) and I'm trying to attach it to an email (using your, but it doesn't seem to be working. Please can you help. I'm using ASP.NET 1.1

Basically I don't want the pdf to be displayed or saved to disk, just emailed. Is this possible?

Here is my code. It's in VB.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim p As Pdf
p = Invoice.CreatePdf()
Dim pdfStream = New MemoryStream



End Sub

Private Sub sendAspEmail(ByRef pdfSteam As MemoryStream)

Dim msg = New Aspose.Email.Message
msg.From = New Aspose.Email.Address("")
msg.ReplyTo = New Aspose.Email.Address("")
msg.AddAddress(New Aspose.Email.Address(""), Aspose.Email.Address.Type.To)
msg.Subject = "Mail subject"
msg.MailPriority = Message.Priority.Highest
msg.Date = DateTime.Now
msg.Confirmation = False
msg.AllowRefusedAddresses = True
Dim x As String
x = "" & "Test email" & ""
Dim htmlBody = New Aspose.Email.TextHtmlBody
htmlBody.Content = x
htmlBody.Charset = "UTF-8"
Dim altBody = New Aspose.Email.AlternativeBody
msg.Body = altBody

Dim attachment = New Aspose.Email.Attachment(pdfSteam, "invoice.pdf", New Aspose.Email.Config.NullTempFileNameProvider)

msg.Send(New SmtpAccount("", 25, "", ""), New ProgressMonitor)

End Sub


Many Thanks

William Roscoe

Hello again,

Just to say don’t worry, I’ve worked it out…

The correct attachment code is…

Dim attachment = New Aspose.Email.Attachment(pdfSteam.GetBuffer, New Aspose.Email.Config.NullTempFileNameProvider) = “invoice.pdf”


Thanks anyway!

Dear dif,

Thanks for your post.

Please feel free to post any problem about Aspose.Email here, we are more than glad to help.

If you wanna quick response for your question, please add my MSN:

Thanks again.