PowerTCP Mail for .NET
Recipients Property
See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Smtp Class : Recipients Property




Use this property to add recipients that will be used for the "RCPT TO" portion of the SMTP envelope.

Syntax

Visual Basic (Declaration) 
<BrowsableAttribute(False)>
Public Property Recipients As MailAddresses
Visual Basic (Usage)Copy Code
Dim instance As Smtp
Dim value As MailAddresses
 
instance.Recipients = value
 
value = instance.Recipients
C# 
[BrowsableAttribute(false)]
public MailAddresses Recipients {get; set;}
Managed Extensions for C++ 
[BrowsableAttribute(false)]
public: __property MailAddresses* get_Recipients();
public: __property void set_Recipients( 
   MailAddresses* value
);
C++/CLI 
[BrowsableAttribute(false)]
public:
property MailAddresses^ Recipients {
   MailAddresses^ get();
   void set (    MailAddresses^ value);
}

Property Value

A MessageAddresses collection specifying the email addresses of the recipients that will be included in the SMTP envelope.

Example

The following example demonstrates using the Smtp component to override the addresses used for the SMTP envelope.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

' First create a message
Dim msg As New MessageStream()

' Add a "TO:" header line
msg.To.Add(New MailAddress("you@test.com"))

' Add a "FROM:" header line
msg.From = New MailAddress("me@test.com")

' Add a "SUBJECT:" header line
msg.Subject = "Test"

' Add some text
msg.Text = "test message"

' If the message is sent now, "me@test.com" would be sent after the SMTP
' "MAIL FROM" command and "you@test.com" would be sent after the SMTP "RCPT
' TO" command. You can override this, however, by explicitly setting the 
' addresses that will be used for the SMTP envelope as the following code demonstrates.

' Explicitly specify the email to use for "MAIL FROM" (This will NOT be included in the header)
Smtp1.MailFrom = New MailAddress("sender@test.com")

' Explicitly specify the email to use for "RCPT TO"; (This will NOT be included in the header)
Smtp1.Recipients.Add(New MailAddress("receiver@test.com"))

' Send the message, this will return an SmtpResult object
Smtp1.Server = "mail.test.com"
Dim result As SmtpResult = Smtp1.Send(msg)

' Check the information about the message sent
Debug.WriteLine("Bytes of data Sent: " + result.SentLength)
Dim ma As MailAddress
For Each ma In result.Recipients
   Debug.WriteLine("Mail sent to: " + ma.Address)
Next

' Output
' --------------------------------
' Bytes of data sent: 477
' Mail sent to: <receiver@test.com>
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

// First create a message
MessageStream msg = new MessageStream();

// Add a "TO:" header line
msg.To.Add(new MailAddress("you@test.com"));

// Add a "FROM:" header line
msg.From = new MailAddress("me@test.com");

// Add a "SUBJECT:" header line
msg.Subject = "Test";

// Add some text
msg.Text = "test message";

// If the message is sent now, "me@test.com" would be sent after the SMTP
// "MAIL FROM" command and "you@test.com" would be sent after the SMTP "RCPT
// TO" command. You can override this, however, by explicitly setting the 
// addresses that will be used for the SMTP envelope as the following code demonstrates.

// Explicitly specify the email to use for "MAIL FROM" (This will NOT be included in the header)
smtp1.MailFrom = new MailAddress("sender@test.com");

// Explicitly specify the email to use for "RCPT TO"; (This will NOT be included in the header)
smtp1.Recipients.Add(new MailAddress("receiver@test.com"));

// Send the message, this will return an SmtpResult object
smtp1.Server = "mail.dart.com";
SmtpResult result = smtp1.Send(msg);

// Check the information about the message sent
Debug.WriteLine("Bytes of data Sent: " + result.SentLength);
foreach(MailAddress ma in result.Recipients)
   Debug.WriteLine("Mail sent to: " + ma.Address);

// Output
// --------------------------------
// Bytes of data sent: 477
// Mail sent to: <receiver@test.com>

Remarks

The SMTP envelope specifies where the email message is sent. If "bob@test.com" is added to the Smtp.Recipients collection, and "jane@test.com" is added as a message header field (perhaps by using the Message.To property) mail will be sent to "bob@test.com" only. If the Smtp.Recipients collection is empty, and "jane@test.com" is added as a message header line (by using the Message.To property) the SMTP envelope will be derived by the message header and mail will be sent to "jane@test.com".

Use this property if you want to explicitly specify the recipient in the SMTP envelope. The value of this property will NOT be added as a message header line.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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