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



Glossary Item Box

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

To quickly and easily send a "forward" 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 Forward method, you must have a complete MessageStream object to forward. 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 "forwarded" MessageStream using the Forward method.
    C# Copy Code
    MessageStream msgForward = msg.Forward("This is the new text.");
    Visual Basic Copy Code
    Dim msgForward as MessageStream = msg.Forward("This is the new text.")
  6. The "forwarded" message has been created, the only remaining thing to do is set the sender and receiver.
    C# Copy Code
    msgForward.To.Add(new MailAddress("forwardedaddress@test.com"));
    msgForward.From = new MailAddress(sender@test.com);
    Visual Basic Copy Code
    msgForward.To.Add(new MailAddress("forwardedaddress@test.com"))
    msgForward.From = new MailAddress(sender@test.com)
  7. The "forwarded message has now been created. Send the message.
    C# Copy Code
    // First set the server.
    smtp1.Server = "mail.test.com";
    
    // Then send.
    smtp1.Send(msgForward);
    Visual Basic Copy Code
    ' First set the server.
    Smtp1.Server = "mail.test.com"
    
    ' Then send.
    Smtp1.Send(msgForward)
  8. Compile and run the application.
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.