Delphi - Indy - GMail Traction Saving

I am using Indy under Delphi to send a message through a gmail account using the TIdSMTP and TIdMessage components. It works absolutely fine.

However, my client asked me to save the message in the DRAFTS folder so that he could make changes to the (programmed) message before sending it.

The GMail API should support this, but the examples provided are not in Delphi / Indy formats ... I am looking for minimal programming changes, so I would like to know if this is possible in Indy components? TIdMessage allows the use of the "mfDraft" flag, but this does not prevent the message from being sent immediately when using IdSMTP1.Send

+6
source share
2 answers

SMTP does not have a draft concept. You should use IMAP instead.

Use TIdIMAP4 to log in to your GMail account, call its SelectMailBox() method to select the draft folder, and then call one of the AppendMsg...() methods to store the draft letter in the folder as needed.

If you want to make changes to the draft before sending it, you will need to extract the current draft from the folder (one of the Retrieve...() or UIDRetrieve...() methods) and edit as necessary, and then delete the current draft from the folder (method DeleteMsgs() or UIDDeleteMsg() ) and add a new draft to the folder.

To send a project, you will need to extract and delete it from the draft folder, and then use SMTP to send.

+3
source

OK, for those who read this topic in the future ... we need a code here: (gebr and ww are username and password)

 procedure DraftGMail(Info:TIdMessage; gebr,ww:string); var IdIMAP41:TIdIMAP4; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; begin IdSSLIOHandlerSocketOpenSSL1:= TIdSSLIOHandlerSocketOpenSSL.create; try IdSSLIOHandlerSocketOpenSSL1.Destination := 'imap.gmail.com:993'; IdSSLIOHandlerSocketOpenSSL1.host := 'imap.gmail.com'; // IdSSLIOHandlerSocketOpenSSL1.MaxLineAction := maException; IdSSLIOHandlerSocketOpenSSL1.Port := 993; IdSSLIOHandlerSocketOpenSSL1.DefaultPort := 0; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv3; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.SSLversions := [sslvSSLv3]; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmUnassigned; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode := []; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 0; IdIMAP41:= TIdIMAP4.create; try IdIMAP41.IOHandler := IdSSLIOHandlerSocketOpenSSL1; IdIMAP41.Host := 'imap.gmail.com'; IdIMAP41.Password := ww; IdIMAP41.Port := 993; // IdSMTP1.SASLMechanisms := <>; IdIMAP41.UseTLS := utUseImplicitTLS; IdIMAP41.Username := gebr; IdIMAP41.Connect; // IdIMAP41.ListMailBoxes(Boxes); IdIMAP41.SelectMailbox('[Gmail]/Drafts'); IdIMAP41.AppendMsg('[Gmail]/Drafts',Info); IdIMAP41.Disconnect; finally FreeAndNil(IdIMAP41); end; finally FreeAndNil(IdSSLIOHandlerSocketOpenSSL1); end; end; 
+2
source

All Articles