Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Indy - saving GMail draft

I've been using Indy under Delphi to send message via a gmail account, using the TIdSMTP and TIdMessage components. This works absolutely fine.

However, my client has requested to save the message to the DRAFTS folder to allow him to make changes to the (programatically created) message before actually sending it.

GMail API is supposed to support this, but the provided examples are not in Delphi/Indy formats... I'm looking for minimal programming changes so I'd like to know if it is possible in the Indy components too? TIdMessage allows for a "mfDraft" flag, but this doesn't prevent the message from immediatly being sent when using IdSMTP1.Send

like image 495
Jur Avatar asked Nov 01 '15 10:11

Jur


1 Answers

SMTP has no concept of drafts. You have to use IMAP instead.

Use TIdIMAP4 to login to the GMail account, call its SelectMailBox() method to select the draft folder, and then call one of its AppendMsg...() methods to store a draft of the email into the folder as needed.

If you want to make changes to a draft before sending it, you will have to retrieve the current draft from the folder (one of the Retrieve...() or UIDRetrieve...() methods) and edit is as needed, then delete the current draft from the folder (the DeleteMsgs() or UIDDeleteMsg() method), and append the new draft into the folder.

To actually send a draft, you will have to retrieve and remove it from the draft folder, and then use SMTP to send it.

like image 192
Remy Lebeau Avatar answered Oct 02 '22 12:10

Remy Lebeau