Free Support Forum - aspose.com

Emailing a pdf stream as an attachment

Hello,

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 aspose.email), 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
p.Save(pdfStream)

sendAspEmail(pdfStream)

Response.End()


End Sub


Private Sub sendAspEmail(ByRef pdfSteam As MemoryStream)

Dim msg = New Aspose.Email.Message
msg.From = New Aspose.Email.Address("email@home.com")
msg.ReplyTo = New Aspose.Email.Address("email@home.com")
msg.AddAddress(New Aspose.Email.Address("email@home.com"), 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
altBody.AddPart(htmlBody)
msg.Body = altBody

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

msg.Send(New SmtpAccount("relay.plus.net", 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)

attachment.name = “invoice.pdf”

msg.AddAttachment(attachment)



Thanks anyway!
Will

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: guangzhou@aspose.com

Thanks again.
kyle