PowerTCP Mail for .NET
Sending to Multiple Recipients
Send comments on this topic.



Glossary Item Box

Often, you may have to send an email message to multiple types of recipients (such as carbon copy or blind carbon copy. PowerTCP Mail for .NET makes sending to multiple types of recipients easy to manage, by representing these types as collections of the MessageStream object.

To send mail to multiple recipients, 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. Email messages are represented by MessageStream objects. Create a MessageStream object. 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 "From" and "Subject"
    msg.From.Add(new MailAddress("me@myserver.com"));
    msg.Subject = "Test Message";
    
    // Set the message text
    msg.Text = "This is a test message";
    Visual Basic Copy Code
    ' Create a MessageStream 
    Dim msg As New MessageStream()
    
    ' Set "From" and "Subject"
    msg.From = New MailAddress("me@myserver.com")
    msg.Subject = "Test Message"
    
    ' Set the message text
    msg.Text = "This is a test message"
  5. Add a couple of normal recipients. These will be listed under the "TO:" header of the message, and will be sent after the "RCPT TO" command.
    C# Copy Code
    // Add a couple of normal recipients.
    msg.To.Add(new MailAddress("email1@yourserver.com"));
    msg.To.Add(new MailAddress(email2@yourserver.com));
    Visual Basic Copy Code
    ' Add a couple of normal recipients.
    msg.To.Add(New MailAddress("email1@yourserver.com"))
    msg.To.Add(New MailAddress(email2@yourserver.com))
  6. Add a "carbon copy" address.
    C# Copy Code
    // Add a CC recipient
    msg.CC.Add(new MailAddress(email3@yourserver.com));
    Visual Basic Copy Code
    ' Add a CC recipient
    msg.CC.Add(New MailAddress(email3@yourserver.com))
  7. Add a "blind carbon copy" address.
    C# Copy Code
    // Add a BCC recipient
    msg.BCC.Add(new MailAddress(email4@yourserver.com));
    Visual Basic Copy Code
    ' Add a BCC recipient
    msg.BCC.Add(New MailAddress(email4@yourserver.com))
  8. Send the message. The Send method returns an SmtpResult, which can be checked to see the mail server's response to each mail address.
    C# Copy Code
    // Send the message.
    smtp1.Server = "mail.test.com";
    SmtpResult result = smtp1.Send(msg);
                            
    // Check the response from the server to each address.
    foreach(MailAddress ma in result.Recipients)
       Debug.WriteLine(ma.ServerResponse.ToString());
    Visual Basic Copy Code
    ' Send the message.
    smtp1.Server = "mail.test.com"
    Dim result As SmtpResult = smtp1.Send(msg)
                            
    ' Check the response from the server to each address.
    Dim ma as MailAddress
    For Each ma in result.Recipients
       Debug.WriteLine(ma.ServerResponse.ToString())
    Next
  9. Compile and run the application.

 

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.