PowerTCP Mail for .NET
Replying To A Message
Send comments on this topic.



Glossary Item Box

The MessageStream object has a Reply method, which returns a MessageStream, created as a "reply" message to the original MessageStream.

To quickly and easily send a "reply" message, use the following steps.

  1. Add the Smtp component to a new form.
  2. Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET). Place the following code at the top of your file.
    C# Copy Code
    using Dart.PowerTCP.Mail;
    Visual Basic Copy Code
    Imports Dart.PowerTCP.Mail
  3. Add a button to the form.
  4. In order to use the Reply method, you must have a complete MessageStream object to reply to. Normally, this will be done by accessing a message retrieved using the Pop component. For the purposes of this walk-through, however, a MessageStream will be created. Place the following code in the Click event of the button added to the form in step 3.
    C# Copy Code
    // Create a MessageStream 
    MessageStream msg = new MessageStream();
    
    // Set "To", "From", and "Subject"
    msg.To.Add(new MailAddress("you@yourserver.com"));
    msg.CC.Add(new MailAddress("you2@yourserver2.com"));
    msg.From = new MailAddress("me@myserver.com");
    msg.Subject = "The original message.";
    
    // Set the message text
    msg.Text = "This is the original message.";
    
    // Add an attachment
    msg.Attachments.Add("C:\\Test\\file1.txt");
    Visual Basic Copy Code
    ' Create a MessageStream 
    Dim msg As New MessageStream()
    
    ' Set "To", "From", and "Subject"
    msg.To.Add(New MailAddress("you@yourserver.com"))
    msg.CC.Add(New MailAddress("you2@yourserver2.com"))
    msg.From = New MailAddress("me@myserver.com")
    msg.Subject = "The original message."
    
    ' Set the message text
    msg.Text = "This is the original message."
    
    ' Add an attachment
    msg.Attachments.Add("C:\Test\file1.txt")
  5. Now that there is a MessageStream representing the original message, create a "reply" MessageStream.
    C# Copy Code
    MessageStream msgReply = msg.Reply(true, "This is the reply message.");
    Visual Basic Copy Code
    Dim msgReply as MessageStream = msg.Reply(true, "This is the reply message.")
  6. The "reply" message has been created, the only remaining headers to set should be "From".
    C# Copy Code
    // Set the "From" header
    msgReply.From = new MailAddress(me@myserver.com);
    Visual Basic Copy Code
    ' Set the "From" header
    msgReply.From = new MailAddress(me@myserver.com)
  7. The "reply" message has now been created. Send the message.
    C# Copy Code
    // First set the server.
    smtp1.Server = "mail.test.com";
    
    // Then send.
    smtp1.Send(msgReply);
    Visual Basic Copy Code
    ' First set the server.
    Smtp1.Server = "mail.test.com"
    
    ' Then send.
    Smtp1.Send(msgReply)
  8. Compile and run the application.
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.