以下のサンプルコードは、メールボックスを作成、名前変更、および削除する方法を示します。また、メールボックスの購読を開始および停止する方法も示します。
private void doMailboxFunctions(object sender)
{
// サーバーとアカウントの情報を設定します。
imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session));
imap1.Session.Username = myUsername;
imap1.Session.Password = myPassword;
// 接続してアカウントにログインします。
imap1.Connect();
imap1.Authenticate();
// メールボックスを作成します。
Mailbox newBox = imap1.Mailboxes.Add("My_New_Box");
// メールボックスの購読を開始し、購読リストをチェックします。
newBox.Subscribe();
// 購読しているすべてのメールボックスを取得します。
List<Mailbox> list = imap1.List("", "%", true).ToList<Mailbox>();
if (!list.Contains(newBox)) throw new Exception("Server did not subscribe the mailbox.");
// メールボックスの購読を停止し、購読リストをチェックします。
newBox.Unsubscribe();
list = imap1.List("", "%", true).ToList<Mailbox>();
if (list.Contains(newBox)) throw new Exception("Server did not unsubscribe the mailbox.");
// メールボックスの名前を変更してから、メールボックスを削除します。
newBox.Name = newBox.Name + "_Renamed";
imap1.Mailboxes.Remove(newBox);
// セッションから適切にログアウトします。
imap1.Close();
}
Private Sub doMailboxFunctions(ByVal sender As Object)
' サーバーとアカウントの情報を設定します。
imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session))
imap1.Session.Username = myUsername
imap1.Session.Password = myPassword
' 接続してアカウントにログインします。
imap1.Connect()
imap1.Authenticate()
' メールボックスを作成します。
Dim newBox As Mailbox = imap1.Mailboxes.Add("My_New_Box")
' メールボックスの購読を開始し、購読リストをチェックします。
newBox.Subscribe()
' 購読しているすべてのメールボックスを取得します。
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
' メールボックスの購読を停止し、購読リストをチェックします。
newBox.Unsubscribe()
list = imap1.List("", "%", True).ToList()
If list.Contains(newBox) Then
Throw New Exception("Server did not unsubscribe the mailbox.")
End If
' メールボックスの名前を変更してから、メールボックスを削除します。
newBox.Name = newBox.Name & "_Renamed"
imap1.Mailboxes.Remove(newBox)
' セッションから適切にログアウトします。
imap1.Close()
End Sub