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.
- Add the Smtp component to a new form.
- 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 Codeusing Dart.PowerTCP.Mail;Visual Basic
Copy CodeImports Dart.PowerTCP.Mail - Add a button to the form.
- 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")
- Now that there is a MessageStream representing the original message, create a "forwarded" MessageStream using the Forward method.
C#
Copy CodeMessageStream msgForward = msg.Forward("This is the new text.");Visual Basic
Copy CodeDim msgForward as MessageStream = msg.Forward("This is the new text.")
- The "forwarded" message has been created, the only remaining thing to do is set the sender and receiver.
C#
Copy CodemsgForward.To.Add(new MailAddress("forwardedaddress@test.com")); msgForward.From = new MailAddress(sender@test.com);
Visual Basic
Copy CodemsgForward.To.Add(new MailAddress("forwardedaddress@test.com")) msgForward.From = new MailAddress(sender@test.com)
- 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)
- Compile and run the application.