Glossary Item Box

PowerWEB TextBox for ASP.NET

Integrating with Mail Applications

The PowerWEB TextBox for ASP.NET is ideally suited for creating Web Mail solutions by handling the HTML message body of an email, including handling image insertion and attachment uploads. This fits perfectly with the PowerTCP Mail for .NET product, which is geared to not only providing mail communications components such as Smtp, Pop, and Imap, but also includes a powerful MIME message encoder/decoder called the MessageStream, which is capable of properly encoding an HTML message body. For a live sample and source code download, please visit http://www.dart.com/PowerWEB/textbox_samples.asp. Because there is more to creating a Web Mail application than just feeding in HTML, the complete code for the sample is only available online. The online sample demonstrates session management, attachment management, and other requirements for the application. A general, but incomplete code snippet is seen below:

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click

   ' Create instance of Smtp Component
   Smtp1 = New Smtp()

   ' Save the message to the session directory.SessionMessageFile has already been initialized with the path information
   ' in SetSessionDirectories, visible online.
   Dim Stream As New FileStream(SessionMessageFile, FileMode.Create)
   Dim Writer As New StreamWriter(Stream)
   Writer.Write(HtmlBox1.Text)
   Writer.Flush()
   Stream.Close()

   ' Create a new message stream, using the message file as source
   Dim msg As New MessageStream(SessionMessageFile)

   ' Set fields. These are guarenteed to have content, because of the InputValidators
   msg.From = New MailAddress(txtFrom.Text)
   msg.To.Add(New MailAddress(txtTo.Text))
   msg.Subject = txtSubject.Text

   ' Add any uploaded files as attachments
   ' AttachDir has been set in SetSessionDirectories, visible online.
   Dim Attachment As String
   Dim Attachments() As String = Directory.GetFiles(AttachDir)
   For Each Attachment In Attachments
      msg.Attachments.Add(Attachment)
   Next

   ' Create SmtpResult object which is returned by the Send operation
   ' and provides data about the success/failure of the Send operation.
   Dim resultObj As Dart.PowerTCP.Mail.SmtpResult

   Try
      ' Send the message (change the mail server to your mail server)
      Smtp1.Server = "mail.dart.com"
      resultObj = Smtp1.Send(msg)
      
      ' Save the result object to a session variable, so results
      ' can be displayed on the next page.
      Page.Session.Add("resultObj", resultObj)

      ' Send to notification page.
      Page.Response.Redirect("SmtpResult.aspx?result=success", False)
   Catch ex As Exception
      ' Save the Exception object to a session variable, so results
      ' can be displayed on the next page.
      AddTextToDebugLog("# ERROR: " + ex.ToString)
      Page.Session.Add("ex", ex)
      Page.Response.Redirect("SmtpResult.aspx?result=failure")
   End Try
End Sub

In This Section

Using HtmlBox Skins
Describes how skins can be applied to enhance the HtmlBox and how to create your own skins.
Creating a Custom Button
Describes how to create a custom button to call a JavaScript function.
Creating a Custom Dialog Button
Describes how to create a custom button which launches a dialog when clicked.
Creating a Custom Menu Button
Describes how to create a custom button which opens a menu when clicked.
Creating a Custom DropDown
Describes how to create a custom dropdown box.
Creating a Custom Toolbar Image
Describes how to create a custom toolbar image.
Creating Custom Toolbar Text
Describes how to create custom toolbar text.
Customizing File Uploads
Describes the built in upload support and how it can be customized.
Integrating Spell Checking
Provides steps of how to use a spell checker with the editor.
Integrating with Mail Applications
Provides information on how to integrate the HtmlBox with PowerTCP Mail for .NET to create mail applications which are capable of mailing HTML email messages.

 

 


Send comments on this topic.

Documentation version 3.2.0.0.

© 2009 Dart Communications.  All rights reserved.