Emailing Dynamically Created PDFs

Emailing Dynamically Created PDFs

Support · Oct 25, 2005
Having the ability to create great looking, DynamicPDF documents is one thing but we sometimes need those documents to get to an end user, a customer or a colleague in real time. Well, here is some helpful information that will allow you to email those PDFs from within your DynamicPDF applications. There are three basic steps for getting your PDFs emailed on the fly: 1. Create your PDF using DynamicPDF Generator/Merger for .NET. 2. Using the "Draw" method save that PDF to File. 3. Using the .NET Framework's built in emailing functionality, attach and send the PDF. First, create a PDF. If you are just getting started you can take a look at any of our Merger or Generator for .NET examples for creating DynamicPDFs, http://www.DynamicPDF.com/Products/MergerForNET/Examples.csp , http://www.DynamicPDF.com/Products/GeneratorForNET/Examples.csp . Second, you will need to use the "Draw" method and save the PDF to an actual location on disk. Saving the file to an actual location on disk is required as the .NET Framework's emailing functionality does not have the ability to attach a file from memory. (There are third party tools out there that will allow you to attach a file from a memory stream if required.) Finally, use the System.Web.Mail objects to create, attached and send the email. Create a new "MailMessage" object and then set its properties (to, from, body, etc.). Then add an attachment to the message as a new "MailAttachment" specifying the file path to the PDF. Lastly, make sure that you have specified an SMTP server to send from using the "SmtpMail.SmtpServer" static (Shared in VB.NET) property. Here is some sample code for both C# and VB.NET C# ceTe.DynamicPDF.Document objDocument = new ceTe.DynamicPDF.Document(); //Create DynamicPDF Document Here objDocument.Draw( @"C:\temp\document.pdf" ); MailMessage objMessage = new MailMessage(); objMessage.To = "receiver@domain.com"; objMessage.From = "sender@domain.com"; objMessage.Subject = "Attached PDF Email"; objMessage.Body = "This is the body of the email. The DynamicPDF is attached"; SmtpMail.SmtpServer = "mail.domain.net"; objMessage.Attachments.Add( new MailAttachment( @"C:\temp\document.pdf" ) ); SmtpMail.Send( objMessage ); VB.NET Dim objDocument As ceTe.DynamicPDF.Document = New ceTe.DynamicPDF.Document 'Create DynamicPDF Document Here objDocument.Draw("C:\temp\document.pdf") Dim objMessage As MailMessage = New MailMessage objMessage.To = "receiver@domain.com" objMessage.From = "sender@domain.com" objMessage.Subject = "Attached PDF Email" objMessage.Body = "This is the body of the email. The DynamicPDF is attached" SmtpMail.SmtpServer = "mail.domain.net" objMessage.Attachments.Add(New MailAttachment("C:\temp\document.pdf")) SmtpMail.Send(objMessage)

Re: Emailing Dynamically Created PDFs

Forum member · Apr 3, 2006
Is there no other way to attach the pdf to the email with saving and loading the file from the harddisk? For websites it's more difficult to save and write to harddisks. Is it possible to do it via the stream objects? Hans

Re: Emailing Dynamically Created PDFs

Support · Apr 3, 2006
Hans, Using the Frameworks built-in emailing capabilities, no, emailing the PDF via a stream is not a possibility. That method requires the PDF to exist on disk before attaching. This however is one of the very reasons that ceTe Software created and is about to release its all new FireMail product line. FireMail allows you create, attach documents to and send emails all from within your .NET application. Attachments can come from a file, a stream object or a byte array providing a robust solution for emailing any documents (including PDF). Currently the FireMail evaluation version is included with the Generator 4.0 Community edition download, http://www.DynamicPDF.com/Products/GeneratorForNET/Download.csp . Please download Generator v4.0 to experience our new FireMail capabilities. Thanks, ceTe Software Support Team

Re: Emailing Dynamically Created PDFs

Forum member · Apr 3, 2006
I didn't find a sample with combination of Dynamic en firemail Is this like: MyDocument.Draw( MyStream ) ptMessage.Attachments.Add(MyStream, "Test.pdf") ptMessage.Send(smtpServer) Or could you provide the right code for sending on the fly created pdf's? Thanks Hans

Re: Emailing Dynamically Created PDFs

Support · Apr 3, 2006
Hans, Have you downloaded the Version 4.0 of Generator for .NET? This includes with it FireMail v1.0. Also with the download is the Help Library which includes a section for FireMail. In the Help Library you will find a section on attaching documents and it does show how to attach a file from a stream. The Help Library is also available online. The page I was referring to can also be found here: http://www.DynamicPDF.com/Support/NET_Help_Library_06_03/html/Attachments.html Thanks, ceTe Software Support Team

Re: Emailing Dynamically Created PDFs

Forum member · Apr 3, 2006
Yes I have seen that in the helpfile, but this is the part after creating a .jpg file. This is only the Firemail part and nothing about the part of pdf creation. I'm missing the link between the creation of the stream out of the Dynamicpdf creater and the stream to Firemail. I'm missing the lines with VB code between those two parts. Hans