B4J Question [SOLVED]Deleting Emails After Download

Philip Chatzigeorgiadis

Active Member
Licensed User
Longtime User
I am downloading emails from Gmail, using the code below.
I want the emails to be deleted after download completion.
Taking into consideration this thread, https://www.b4x.com/android/forum/threads/delete-email-based-on-subject-with-pop3-solved.48670/
I have included true as the last parameter when calling pop.downloadmessage.
In addition, in Gmail's Settings> Forwarding and POP/IMAP, I have selected:
"2. When messages are accessed with POP : delete Gmail's copy".

However, the emails are still not deleted from gmail server, after I download them.
What am I missing?

B4X:
    Dim pop As POP3
    pop.Initialize("pop.gmail.com", 995, "[email protected]", "XXXXX", "pop")
    pop.UseSSL = True
    Dim cs As CustomTrustManager
    cs.InitializeAcceptAll
    pop.SetCustomSSLTrustManager(cs)
    wait for (pop.ListMessages) pop_ListCompleted (ListOK As Boolean, Messages As Map)
    Log ("List Success: " & ListOK)
    If ListOK = False Then
        Log(LastException.Message)
    Else
        For i = 0 To Messages.Size - 1
            wait for (pop.DownloadMessage(Messages.GetKeyAt(i),True)) pop_DownloadCompleted (Success As Boolean, MessageId As Int, MessageText As String)
            If Success = False Then
                Log(LastException.Message)
            Else
                'Parse the mail
                mailcount=mailcount+1
                MailParser.ParseMail(MessageText, "C:\Users\user\Google Drive")
            End If
        Next
    End If
    pop.close
 

Philip Chatzigeorgiadis

Active Member
Licensed User
Longtime User
The code above actually deleted the incoming emails.
In my failed deletion tests, the incoming email was sent from the same account (i.e. the email account was sending email to itself - for testing purposes).
These emails were shown as not deleted from the gmail's Inbox , because they were still present at the gmail's Sent folder.
 
Upvote 0
Top