Dart.Mail Namespace > MailboxCollection Class > Add Method : Add(String) Method |
Dim instance As MailboxCollection Dim name As String Dim value As Mailbox value = instance.Add(name)
Exception | Description |
---|---|
ProtocolException | Bad IMAP protocol response received from server. |
System.Net.Sockets.SocketException | The requested address is not valid in its context. |
System.InvalidOperationException | Attempt to illegally modify a server-side collection. |
Creates a new mailbox on the server with the specified name by sending the IMAP CREATE command. The new mailbox will be created under the currently selected (parent) mailbox. If there is no parent for this mailbox, 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.
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