Glossary Item Box

PowerTCP Mail for .NET

Forwarding A Message

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. For instructions on how to do this see Placing Components on a Form.
  2. Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET).

    [Visual Basic, C#] Place the following code at the top of your file.

    [C#]
    using Dart.PowerTCP.Mail;
    
    [Visual Basic]
    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.

    [Visual Basic, C#] Place the following code in the Click event of the button added to the form in step 3.

    [C#]
    // 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]
    ' 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.

    [Visual Basic, C#]

    [C#]
    MessageStream msgForward = msg.Forward("This is the new text.");
    
    [Visual Basic]
    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.

    [Visual Basic, C#]

    [C#]
    msgForward.To.Add(new MailAddress("forwardedaddress@test.com"));
    msgForward.From = new MailAddress("sender@test.com");
    
    [Visual Basic]
    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.

    [Visual Basic, C#]

    [C#]
    // First set the server.
    smtp1.Server = "mail.test.com";
    
    // Then send.
    smtp1.Send(msgForward);
    
    [Visual Basic]
    ' First set the server.
    Smtp1.Server = "mail.test.com"
    
    ' Then send.
    Smtp1.Send(msgForward)
    
  8. Compile and run the application.

 

In This Section

MIME vs Non-MIME
Dscusses MIME and non-MIME message formats.
Sending Mail Quickly
Provides a description of the simplest and easiest way to send a simple text email message.
Sending Mail To Multiple Recipients
Provides an overview of how to send email to several types of recipients.
Sending Mail With Attachments
Provides a description of the simplest and easiest way to send an email message with attachments.
Replying To A Message
Provides a description of how a reply message can be created using the MessageStream.Reply method.
Forwarding A Message
Provides a description of how a forwarded message can be created using the Forward method.
Sending HTML Mail
Provides a description of the simplest and easiest way to send HTML email.
Sending Mail Asynchronously
Provides an overview of how to send an email message asynchronously.
Displaying Progress When Sending Mail
Provides a description of how to display sending progress when sending mail.
Adding Header Lines
Provides a description of how to set headers (including custom headers) and how to access those headers within your application.
Sending Commands To An SMTP Server
Provides an description of how to send any command (including custom commands outside of the SMTP specification) to an SMTP server.
Sending Mail With DSN
Provides a description of how to send a message using DSN (Delivery Status Notification).
Storing And Loading Messages
Provides a description of how to save a message to a stream or disk, and how to create a message from a saved message on stream or disk.
Making a Trace Log When Sending Mail
Provides a description of how to create a log file containing all data and commands sent or received over the TCP connection.

 

 


Send comments on this topic.

Documentation version 3.1.

© 2009 Dart Communications.  All rights reserved.