Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Delete Email from an IMAP Mailbox C# example to delete email from an IMAP mailbox. // Delete all email in the mailbox with "#SPAM#" in the subject.
private void button8_Click(object sender, System.EventArgs e)
{
Chilkat.Imap imap = new Chilkat.Imap();
imap.UnlockComponent("Anything for 30-day trial");
// If your IMAP server needs SSL, set the Ssl property = true
// and set the IMAP port to 993.
// imap.Ssl = true;
// imap.Port = 993;
imap.Connect("mail.chilkatsoft.com");
// Login to an email account.
bool b = imap.Login("myLogin", "myPassword");
if (!b)
{
MessageBox.Show("Login Failed!");
return;
}
// Select the mailbox to read.
b = imap.SelectMailbox("INBOX");
if (!b)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Get the UIDs for all e-mail with "#SPAM#" in the Subject.
// (The pound sign is NOT a special (wildcard) character.)
bool fetchUids = true;
Chilkat.MessageSet mset = imap.Search("SUBJECT \"#SPAM#\"",fetchUids);
// Mark all the messages in the set for deletion
// Passing a 1 in the last argument marks each message for deletion,
// passing a 0 un-deletes the email. However once the email is
// expunged, it cannot be un-deleted.
b = imap.SetFlags(mset, "Deleted", 1);
if (!b)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// The messages are deleted when expunged, so do it here
// (and also close the mailbox)
b = imap.ExpungeAndClose();
if (!b)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Disconnect from the IMAP server.
imap.Logout();
imap.Disconnect();
MessageBox.Show("Finished!");
}
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.