Deleting a mail using IMAP

imap = Net::IMAP.new(‘IP’)
imap.login(‘username’, ‘password’)
imap.select(‘INBOX’)

if not imap.list(”, ‘TRASH’) #Create a TRASH Folder if it doesn’t exist
imap.create(‘TRASH’)
end

imap.copy(message_id, “TRASH”) #copy the message to the TRASH
imap.store(message_id, “+FLAGS”, [:Deleted]) #Mark Deleted in INBOX

imap.expunge #Remove from INBOX

The above moves the mail to the TRASH….
To permanently delete, you can avoid copying the message to trash or mark it as deleted later and expunge!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s