PowerTCP Mail for .NET
Name Property (Mailbox)
Example 




Gets or sets the "short" name of the mailbox, excluding any parent mailbox.
Syntax
Public Property Name As String
Dim instance As Mailbox
Dim value As String
 
instance.Name = value
 
value = instance.Name
public string Name {get; set;}
public: __property string* get_Name();
public: __property void set_Name( 
   string* value
);
public:
property String^ Name {
   String^ get();
   void set (    String^ value);
}

Property Value

A string representing the "short" name of the mailbox.
Remarks

For example, with a mailbox named:

            "inbox\archives\user"
            

the Mailbox name-related properties would be as follows:

Property Value
Mailbox.Name "user"
Mailbox.FullName "inbox\archives\user"

Setting this property sends a RENAME command to the server. This will only rename the "short" name, which has some limitations. For example, to rename

            "company/users/bob"
            
to
            "company/users/bobjohnson"
            
set Mailbox.Name to "bobjohnson". However, to rename
            "company/users/bob"
            
to
            "archive/bobbackup"
            
set FullName to "archive/bobbackup".

"&" is represented when sent as "&-". Anything between an "&" and a "-" is converted to Unicode.

Setting this property closes the selected mailbox by setting SelectedMailbox to null.

Example
This example demonstrates how to create, rename and delete a mailbox. It also shows how to subscribe and unsubscribe a mailbox.
private void doMailboxFunctions(object sender)
{
    //Configure server and account info
    imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session));
    imap1.Session.Username = myUsername;
    imap1.Session.Password = myPassword;

    //Connect and log into the account
    imap1.Connect();
    imap1.Authenticate();

    //Create a mailbox
    Mailbox newBox = imap1.Mailboxes.Add("My_New_Box");

    //Subscribe the mailbox and check the subscribed list
    newBox.Subscribe();
    //Get all subscribed mailboxes
    List<Mailbox> list = imap1.List("", "%", true).ToList<Mailbox>();
    if (!list.Contains(newBox)) throw new Exception("Server did not subscribe the mailbox.");

    //Unsubscribe the mailbox and check the subscribed list
    newBox.Unsubscribe();
    list = imap1.List("", "%", true).ToList<Mailbox>();
    if (list.Contains(newBox)) throw new Exception("Server did not unsubscribe the mailbox.");

    //Rename the mailbox and then delete it
    newBox.Name = newBox.Name + "_Renamed";
    imap1.Mailboxes.Remove(newBox);

    //Gracefully logout of the session
    imap1.Close();
}
Private Sub doMailboxFunctions(ByVal sender As Object)
    'Configure server and account info
    imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session))
    imap1.Session.Username = myUsername
    imap1.Session.Password = myPassword

    'Connect and log into the account
    imap1.Connect()
    imap1.Authenticate()

    'Create a mailbox
    Dim newBox As Mailbox = imap1.Mailboxes.Add("My_New_Box")

    'Subscribe the mailbox and check the subscribed list
    newBox.Subscribe()
    'Get all subscribed mailboxes
    Dim list As List(Of Mailbox) = imap1.List("", "%", True).ToList()
    If Not list.Contains(newBox) Then
        Throw New Exception("Server did not subscribe the mailbox.")
    End If

    'Unsubscribe the mailbox and check the subscribed list
    newBox.Unsubscribe()
    list = imap1.List("", "%", True).ToList()
    If list.Contains(newBox) Then
        Throw New Exception("Server did not unsubscribe the mailbox.")
    End If

    'Rename the mailbox and then delete it
    newBox.Name = newBox.Name & "_Renamed"
    imap1.Mailboxes.Remove(newBox)

    'Gracefully logout of the session
    imap1.Close()
End Sub
See Also

Reference

Mailbox Class
Mailbox Members


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic