Basic Principles of programming. How to send an email from a PDF form submission. Send either Flattened PDF, Editable PDF, or FDF Data to any recipient using ASP.net and the FDF Toolkit .net component.
Rules: Make sure when posting PDF Data to a buffer, do not post any HTML along with PDF Data. Remove any header information by Declaring Response.Clear() before posting any PDF or PDF Data MIME type.
Notes: Flattening the pdf form can be set with the true or false switch in the FDFDoc.PDFMergeFDF2Buf function FDF Toolkit .net component.
Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Imports FDFApp.Mail
Imports System.Web.Mail
Imports System.Web.Mail.MailFormat
Imports System.Web.Mail.SmtpMail
Private URLPath As String = Request.Url.ToString
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim action As String = Request("act") & ""
Select Case action.ToLower
Case "fdf"
Send_Email(1)
Case "pdflat"
Send_Email(2)
Case "pdfedit"
Send_Email(3)
Case else
Send_Email(1)
End Select
End Sub
Private Function Send_Email(Optional ByVal AttachmentType As Integer = 1, Optional ByVal Use_Remote_SMTP As Boolean = False) As Boolean
Try
Dim FDFApp As New FDFApp.FDFApp_Class
Dim FDFDoc As New FDFApp.FDFDoc_Class
Dim FDFMail As New FDFApp.Mail.MailMessage
Dim FDFSMTP As New FDFApp.Mail.SMTPServer
Dim FDFEmail As New FDFApp.Mail
FDFMail.Add_Recipient("user@domain.com", "A. Recipient")
Dim strSubj As String = "", strBody As String = "", strFrom As String = "", strTo As String = ""
strSubj = "FDF Attachment"
strBody = "Dear User," & Chr(10) & Chr(10) & _
"See attachment for details." & Chr(10) & Chr(10) & _
"You may need Adobe Reader to view this file." & Chr(10) & _
"http://www.adobe.com/reader/" & Chr(10) & Chr(10) & _
"Regards," & Chr(10) & Chr(10) & "Webmaster@domain.com"
FDFMail.mBody = strBody
FDFMail.mSubject = strSubj
FDFMail.mBodyFormat = Mail.MailFormat.Text
FDFMail.mFrom = "Webmaster (webmaster@domain.com)"
FDFSMTP.SMTPConnectionTimeOut = 100
Dim dr As DataRow
If Use_Remote_SMTP Then
FDFSMTP.SMTPPassword = "password"
FDFSMTP.SMTPUserName = "webmaster@domain.com"
FDFSMTP.SMTPServerName = "smtp.domain.com"
FDFSMTP.SMTPUseAuthentication = FDFSMTP.SMTPAuthenticate.cdoBasic
FDFSMTP.SMTPServerPort = 25
Else
FDFSMTP.SMTPServerName = "localhost"
FDFSMTP.SMTPServerPort = 25
FDFSMTP.SMTPUseAuthentication = FDFSMTP.SMTPAuthenticate.cdoNone
End If
FDFDoc = FDFApp.FDFCreate
'FDFDoc.FDFSetValuesFromDataRow(CType(Session("drData"), DataRow)) FDFDoc = FDFApp.FDFOpenFromStream(Request.InputStream) 'FDFDoc.FDFSetFile(URLPath & "PDFs/filename.pdf")
Select Case AttachmentType
Case 1 ' FDF
FDFDoc.FDFSetTargetFrame = "_self" 'Request("target") & ""
If FDFSMTP.FDFSendEmail(FDFMail, FDFDoc, Server.MapPath("Data/"), True, FDFSMTP.FDFType.FDF) = True Then
FDFDoc.FDFSetStatus("Thank you, your email was sent.")
Else
FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
End If
Case 2 ' PDF Flattened
FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", True)
If FDFSMTP.PDFSendEmail(FDFMail, FDFDoc.PDFData, Server.MapPath("Data/"), True, FDFSMTP.FDFType.PDF) = True Then
FDFDoc.FDFSetStatus("Thank you, your email was sent.")
Else
FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
End If
Case 3 ' PDF Editable
FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", False)
If FDFSMTP.PDFSendEmail(FDFMail, FDFDoc.PDFData, Server.MapPath("Data/"), True, FDFSMTP.FDFType.PDF) = True Then
FDFDoc.FDFSetStatus("Thank you, your email was sent.")
Else
FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
End If
Case Else
FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
End Select
Exit Function
Catch ex As Exception
FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
End Try
Response.Clear()
Response.ContentType = FDFApp.MIMEFDF
Response.BinaryWrite(FDFDoc.FDFSavetoBuf)
End Function
53d15a74-f4a4-49db-b757-1909ae01f183|0|.0