Archived Forum Post

Index of archived forum posts

Question:

Storing a mail in the sent folder of gmail

Aug 22 '17 at 18:14

I can send an E-mail using smtp.gmail.com according to the example https://www.example-code.com/dataflex/smtp_gmailSsl.asp

Then I tried to save this mail in the sent folder of my own gmail account, with the code below, but that didn't work.

Get ComSelectMailbox of hoImap "Sent" to iSuccess returns False.

However, Get ComSelectMailbox of hoImap "Inbox" to iSuccess returns True and the mail can be saved in the inbox.

Shall it be so or do I make anything wrong? IMAP is activated on my gmail account.

Code

//Save the mail on the own gmail account

//  The mail has been sent.  Now save the email to the "Sent" folder
//  on your mail server.  (Your "Sent" folder could be named something else,
//  or you may store the email in any folder of your choosing.)
Get Create (RefClass(cComChilkatImap)) to hoImap
If (not(IsComObjectCreated(hoImap))) Begin
    Send CreateComObject of hoImap
End

//  Anything unlocks the component and begins a fully-functional 30-day trial.
Get ComUnlockComponent of hoMailman "XXXXXXXXXXXXXXXXXXXX" to iSuccess
If (iSuccess <> True) Begin
    Get ComLastErrorText of hoImap to sTemp1
    Showln sTemp1
    Procedure_Return
End

//  Connect to an IMAP server.
//  Use TLS
Set ComSsl of hoImap to True
Set ComPort of hoImap to 993
Get ComConnect of hoImap "imap.gmail.com" to iSuccess
If (iSuccess <> True) Begin
    Get ComLastErrorText of hoImap to sTemp1
    Showln sTemp1
    Procedure_Return
End

//  Login
Get ComLogin of hoImap "XXXXXX@gmail.com" "xyzabcde" to iSuccess
If (iSuccess <> True) Begin
    Get ComLastErrorText of hoImap to sTemp1
    Showln sTemp1
    Procedure_Return
End

//  Upload (save) the email to the "Sent" mailbox.
Get pvComObject of hoEmail to vEmail               
Get ComSelectMailbox of hoImap "Inbox" to iSuccess   //this work
//   Get ComSelectMailbox of hoImap "Sent" to iSuccess  //this doesn't work
If (iSuccess <> True) Begin
    Get ComLastErrorText of hoImap to sTemp1
    Showln sTemp1
    Procedure_Return
End

Get ComUidNext of hoImap to iUidNext

Get pvComObject of hoEmail to vEmail
Get ComAppendMail of hoImap "Inbox" vEmail to iSuccess
//   Get ComAppendMail of hoImap "Sent" vEmail to iSuccess
If (iSuccess <> True) Begin
    Get ComLastErrorText of hoImap to sTemp1
    Showln sTemp1
    Procedure_Return
End

Showln "Email saved to the Inbox folder."
//  Showln "Email saved to the Sent folder."

//  Disconnect from the IMAP server.
Get ComDisconnect of hoImap to iSuccess

Accepted Answer

This was an unnessary question. Now I see that the Emails are automatically stored in the sent folder after they are sent so my code for storing them was not needed.

Sorry for this confusion.

Bengt