« Xojo Meetings for Mon… | Home | One day left for Omeg… »

Upload email to Sent folder via IMAP


As you know you can send emails via the CURL functions in MBS Plugins for Xojo and FileMaker. To have your mails how up in sent folder, you need to upload them to the IMAP server. The following script does it for FileMaker. Key thing is to pass in URL to IMAP Server with name of Mailbox, e.g. "imap://imap.monkeybreadsoftware.de/INBOX.Sent". Than you set the upload option and provide the data to send. Of course you should use SSL, certificate verification and pass in your credentials. So here the FileMaker script from the sample database:
 

Set Variable [ $curl ; Value: MBS("CURL.New") ] 

# Set URL with name of the mailbox included:

Set Variable [ $result ; Value: MBS("CURL.SetOptionURL"; $curl; CURL Test::URL & "/INBOX.Sent") ] 

# We upload

Set Variable [ $result ; Value: MBS("CURL.SetOptionUpload"; $curl; 1) ] 

Set Variable [ $email ; Value: CURL Test::email ] 

Set Variable [ $email ; Value: MBS("Text.ReplaceNewline"; $email; 3) ] 

Set Variable [ $result ; Value: MBS("CURL.SetInputText"; $curl; $email; "UTF-8") ] 

# your credenticals

Set Variable [ $result ; Value: MBS("CURL.SetOptionPassword"; $curl; CURL Test::Password) ] 

Set Variable [ $result ; Value: MBS("CURL.SetOptionUsername"; $curl; CURL Test::Name) ] 

# Maybe use alternative IMAP port?

// Set Variable [ $r ; Value: MBS("CURL.SetOptionPort"; $curl; 143) ] 

# This turns TLS on and requires connection to be encrypted

Set Variable [ $r ; Value: MBS("CURL.SetOptionUseSSL"; $curl; 3) ] 

# force TLS v1.2

Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVersion"; $curl; 6) ] 

# This disables certificate verification, so we accept any: 

Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVerifyHost"; $curl; 0) ] 

Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 0) ] 

# Better with certificates if you have some:

// Set Variable [ $r ; Value: MBS( "CURL.SetOptionCAInfo"; $curl; "/Library/FileMaker Server/certificates.pem") ] 

// Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVerifyHost"; $curl; 2) ] 

// Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 1) ] 

Set Variable [ $result ; Value: MBS("CURL.SetOptionVerbose"; $curl; 1) ] 

# do it!

Set Field [ CURL Test::Result ; MBS("CURL.Perform"; $curl) ] 

# Check result:

Set Field [ CURL Test::debug ; MBS("CURL.GetDebugAsText"; $curl) ] 

Set Variable [ $result ; Value: MBS("CURL.Cleanup"; $curl) ] 


Let me know whether this works fine for you. 
 
For Xojo this translate more or less 1:1 to the CURLSMBS class. The properties have the same name and you just pass email via SetInputData method. Just remember to make sure to use ReplaceLineEndings with EndOfLine.Windows.
14 12 17 - 11:38
No comments

  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.