ASP.net 2.0
Principles of Sending Email with a Editable or Flattened PDF or FDF Attachment with 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 content.
Notes: Flattening the pdf form can be set with the true or false switch in the FDFDoc.PDFMergeFDF2Buf function in the FDF Toolkit .net component.
Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Imports FDFApp.Mail
Imports System.Net.Mail
Imports System.Net.Mail.SmtpClient
Partial Public Class sendmail_01
Inherits System.Web.UI.Page
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.msgBody = strBody
FDFMail.msgSubject = strSubj
'FDFMail.mCc = "User2 (user2@domain.com), User3 (user3@domain.com)"
'FDFMail.mCc = "User4 (user4@domain.com),User5 (user5@domain.com)"
FDFMail.msgBodyFormatIsHTML = False
FDFMail.msgFromAddress = New Net.Mail.MailAddress("webmaster@domain.com", "Webmaster")
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.SMTPServerPort = 25
Else
FDFSMTP.SMTPServerName = "localhost"
FDFSMTP.SMTPServerPort = 25
End If
FDFDoc = FDFApp.FDFCreate
'FDFDoc.FDFSetValuesFromDataRow(CType(Session("drData"), DataRow))
FDFDoc.FDFSetValue("Field_01", "Field_Value_A")
FDFDoc.FDFSetValue("Field_02", "Field_Value_B")
FDFDoc.FDFSetFile(URLPath & "PDFs/filename.pdf")
Select Case AttachmentType
Case 1 ' FDF
FDFDoc.FDFSetTargetFrame = "_self" 'Request("target") & ""
If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.fdf", SMTPServer.FDFType.FDF, False) = True Then
Return True
Else
Return False
Exit Function
End If
Case 2 ' PDF Flattened
FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", True)
If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.pdf", SMTPServer.FDFType.PDF, True) = True Then
Return True
Else
Return False
Exit Function
End If
Case 3 ' PDF Editable
FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", False)
If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.[df", SMTPServer.FDFType.PDF, False) = True Then
Return True
Else
Return False
Exit Function
End If
Case Else
Return False
End Select
Exit Function
Catch ex As Exception
Return False
End Try
End Function
End Class
02b6439f-f7a3-42ad-a99f-3e98970de67e|0|.0