PowerTCP Mail for .NET
Add(String) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > MailboxCollection Class > Add Method : Add(String) Method




name
The name of the newly created mailbox.
Adds a new mailbox to the server.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Add( _
   ByVal name As String _
) As Mailbox
Visual Basic (Usage)Copy Code
Dim instance As MailboxCollection
Dim name As String
Dim value As Mailbox
 
value = instance.Add(name)
C# 
public Mailbox Add( 
   string name
)
Managed Extensions for C++ 
public: Mailbox* Add( 
   string* name
) 
C++/CLI 
public:
Mailbox^ Add( 
   String^ name
) 

Parameters

name
The name of the newly created mailbox.

Return Value

A Mailbox object representing the newly added mailbox.

Exceptions

ExceptionDescription
Dart.PowerTCP.Mail.ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.
System.InvalidOperationExceptionAttempt to illegally modify a server-side collection.

Example

The following example demonstrates appending mailboxes to the server.
Visual BasicCopy Code
Private Sub MailboxCollectionTest()
   ' Login
   Imap1.Login(Server, User, Pass)

   ' Create a new mailbox.
   Imap1.Mailboxes.Add("MyNewBox")

   ' Get the Mailbox in a short variable name to reduce typing.
   Dim Box As New Mailbox = Imap1.Mailboxes("MyNewBox")

   ' APPEND some test messages
   Dim i As Integer
   For i = 0 To 5
      ' Dynamically create a new message
      Dim Msg As New MessageStream()
      Msg.To.Add(New MailAddress("me@test.com"))
      Msg.From = New MailAddress("you@test.com")
      Msg.Subject = "test # " + i
      Msg.Text = "Hello, how are you?"

      ' Append the message
      Box.Messages.Add(msg)
   Next

   ' Refresh the mail box so new messages will be included
   Box.Refresh()

   ' Display a list of the message identifiers.
   Debug.WriteLine(Box.Messages.ToString())

   ' Clear all messages
   Box.Messages.Clear()

   ' Logout
   Imap1.Logout()
End Sub
C#Copy Code
private void MailboxCollectionTest()
{
   // Login
   imap1.Login(Server, User, Pass);

   // Create a new mailbox.
   imap1.Mailboxes.Add("MyNewBox");

   // Get the Mailbox in a short variable name to reduce typing.
   Mailbox box = imap1.Mailboxes["MyNewBox"];

   // APPEND some test messages
   for(int i=0; i < 5; i++)
   {
      // Dynamically create a new message
      MessageStream msg = new MessageStream();
      msg.To.Add(new MailAddress("me@test.com"));
      msg.From = new MailAddress("you@test.com");
      msg.Subject = "test # " + i;
      msg.Text = "Hello, how are you?";

      // Append the message
      box.Messages.Add(msg);
   }

   // Refresh the mail box so new messages will be included
   box.Refresh();

   // Display a list of the message identifiers.
   Debug.WriteLine(box.Messages.ToString());

   // Clear all messages
   box.Messages.Clear();

   // Logout
   imap1.Logout();
}

Remarks

The MailboxCollection.Add method creates a new mailbox on the server using the specified name by sending the IMAP CREATE command. name will be used to create the mailbox "within" the currently selected mailbox by adding name to the parent mailboxes name. If there is no parent of this mailbox, then the new mailbox will be a top-level mailbox.

After calling this method, the MailboxCollection will be automatically updated to reflect the current state of the collection. There is no need to explicitly call MailboxCollection.Refresh.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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