
Cannot Delete IMAP Email by UIDL?
Question:
I'm having problems deleting IMAP mail. As I
read the mail into the bundle the Uidl doesn't seem to get set. So when I
try to delete the mail using:
IMAP.SetFlag(email.Uidl, true, "Deleted", 1)
I get an error saying the message could not be found.
I've tried using the zero-based sequence number and calling:
IMAP.SetFlag(emailID, false, "Deleted", 1)
IMAP.Expunge
The SetFlag method doesn't return an error, but the email doesn't get
deleted either.
I'm using my Exchange account to test this and so I can see the email via
Outlook. Once the app has run the email is still there. Everything has been
dealt with in the attachment but I don't want the processed email remaining
once I've finished with it.
Answer:
The Chilkat Email object is used for emails downloaded from both POP3 and IMAP mail servers. The email.UIDL property only applies to email
downloaded from a POP3 server. IMAP emails have a UID, not a UIDL. (how confusing, and I'm sorry for this...)
To delete an individual email from an IMAP server once you have the email object, do this:
' This is ASP code, but the same method and properties apply to VB.NET, C#, VB6, C++, etc.
' Assuming a mail bundle has already been downloaded from an IMAP server...
' Loop over the bundle and mark emails for deletion
For i = 0 To bundle.MessageCount - 1
Set email = bundle.GetEmail(i)
' If the email subject contains the substring "#SPAM#" then delete it.
if InStr(email.Subject,"#SPAM#") then
Response.write "Marking:" & email.Subject & "<br>"
' Call SetMailFlag, passing the email object, the name of the flag, and the value of the flag.
imap.SetMailFlag email,"Deleted",1
end if
Next
' Permanently removes from the currently selected mailbox
' all messages that have the \Deleted flag set.
imap.Expunge
|