Glossary Item Box
The
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
Send comments on this topic.
Documentation version 3.2.0.0.
© 2009 Dart Communications. All rights reserved.