Receive email headers in the GMail Sent Items folder

My program sends letters to contacts via GMail. This usually works very well, but we noticed that sometimes the letter that my program β€œthinks” that it sent does not actually arrive in Gmail, not to mention the contacts. I thought that I could add a check to the program that accesses the Gmail's Sent Items folder to see if the message is actually sent.

I have code using the TIdPOP3 component, but it loads the headers from the inbox, not from the sent items. My question is: how can I access the headers in the sent items folder?

Below is the code I'm using. This is only test code, so there are no try / finally blocks, etc.

with pop do begin host:= 'pop.gmail.com'; username:= ' someone@gmail.com '; password:= .....; Port:= 995; Connect; if connected then with i:= checkmessages downto 1 do begin msg.clear; // msg is of type TIdMessage if retrieve (i, msg) then listbox1.items.add (msg.subject) end; disconnect end; 
+1
source share
1 answer

To get information related to items submitted, you can use Gmail imap_extensions and TIdIMAP4 .

Try this sample

 {$APPTYPE CONSOLE} uses Classes, SysUtils, IdIMAP4, IdSSLOpenSSL, IdMessageCollection, IdExplicitTLSClientServerBase; procedure GetSentItems; var LIdIMAP4: TIdIMAP4; LIdSSLIOHandlerSocketOpenSSL : TIdSSLIOHandlerSocketOpenSSL; AMailBoxList: TStrings; AMsgList: TIdMessageCollection; i: integer; begin LIdIMAP4 := TIdIMAP4.Create(nil); try LIdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); try LIdSSLIOHandlerSocketOpenSSL.SSLOptions.Method := sslvSSLv3; LIdIMAP4.IOHandler := LIdSSLIOHandlerSocketOpenSSL; LIdIMAP4.Host := 'imap.gmail.com'; LIdIMAP4.Port := 993; LIdIMAP4.UseTLS := utUseImplicitTLS; LIdIMAP4.Username := 'user'; LIdIMAP4.Password := 'password'; LIdIMAP4.Connect; try //list the mail boxes AMailBoxList:=TStringList.Create; try if LIdIMAP4.ListSubscribedMailBoxes(AMailBoxList) then Writeln(AMailBoxList.Text); finally AMailBoxList.Free; end; AMsgList:=TIdMessageCollection.Create(TIdMessageItem); try if LIdIMAP4.SelectMailBox('[Gmail]/Enviados') then //This folder name is localizated in english use [Gmail]/Sent Mail if LIdIMAP4.MailBox.TotalMsgs>0 then if LIdIMAP4.UIDRetrieveAllEnvelopes(AMsgList) then for i := 0 to AMsgList.Count-1 do begin //do your work here Writeln(AMsgList[i].Subject); //list the subject of the sent items end; finally AMsgList.Free; end; finally LIdIMAP4.Disconnect; end; finally LIdSSLIOHandlerSocketOpenSSL.Free; end; finally LIdIMAP4.Free; end; end; begin try GetSentItems; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; readln; end. 
+3
source

Source: https://habr.com/ru/post/1488822/


All Articles