Product Logo

POP3it Pro

Email downloading made easy.

Receive Minimal

Introduction

Receive Minimal example database

This example demonstrates a way to download only a portion of each email. The complete email can then be downloaded at a later time. This allows you to quickly download a “preview” of all your email, and then only download the complete email data for the messages you actually want. For more complex examples of receiving email, check the Example Library site often or subscribe to one of our RSS feeds for updates.

To test the example, you will first need to create an account by clicking the Settings button. POP3it Pro has a built-in Account configuration dialog that will allow you to enter settings for multiple email accounts. To create a new Account, click the + button in the right hand corner, and give the Account a name. You will also need to enter all the applicable settings on the Connection tab. Click Save and then Close when you are finished editing your settings.

When you are ready to download your email, select the Account name in the Account field and click the Check Email button. A new record will be created for each email. When the plug-in is done downloading email, click on an email to view it. You will now be presented with a layout to either download the remaining email data or delete the message. If you click Download, the remaining email data (e.g. body, attachments, etc) will be downloaded. If you choose to delete the email, it will be deleted from your email server and the record will be deleted from the database. Please note, if you have another email client downloading the same email as this database, it may be possible the other email client deletes the email from the mail server before you can completely download or delete email in this database.

Download Example File

FileMaker 7–11 Example

FileMaker 12 Example

Example Explanation

To understand how this example works, open ScriptMaker and edit the Check Email script.

If [ IsEmpty(Messages::CurrentAccount) ] Show Custom Dialog [ Title: “Message”; Message: "You… Exit Script [ ]

The script starts by checking if the Messages::CurrentAccount field is empty. This step just helps catch simple mistakes, because this example database requires you to select an Account name to download email from.

Else Set Field [ Messages::Result; POP3it_StatusWindow( “Show”) & “¶” & POP3it_Adv_Connect( Messages::CurrentAccount ) ]

This shows a status window using the POP3it_StatusWindow function, and then connects to the Account name which is specified in the Messages::CurrentAccount field.

If [ PatternCount( Messages::Result; “ERROR”) > 0 ]

This step checks to see if the Messages:Result field contains the word “ERROR”. If the PatternCount returns a number greater than zero, the If statement will be true. When a function of the plug-in is called (e.g. POP3it_Adv_Connect), it will return (in the field you are setting) a ‘result’, whether it is a success or an error. The previous step that connected was set to the Messages::Result field, so this If statement then checks that field to see if the plug-in returned an error. All errors the plug-in returns will start with ERROR, so a field can always be searched for that keyword when doing error checking. Please note, error checking such as this is very important in your scripts. If you ignore errors the plug-in returns, it will not work as expected, and make problems harder to troubleshoot.

Set Field [ Messages::Result; POP3it_StatusWindow( “Hide” ) & “¶” & Messages::Result ] Show Custom Dialog [ Title: “Message”; Message: "There…] Exit Script [ ] End If

This step hides the status window, shows the user an error message, and exits the script.

Set Field [ Messages::CurrentResult; POP3it_Adv_GoToMessage( “First” ) ]

This step calls the POP3it_Adv_GoToMessage function to go to the first available message on the mail server. You can also specify an exact email number or UIDL to go to, but for this example we are starting with the very first email, as specified by the “First” parameter.

If [ PatternCount( Messages::CurrentResult; “ERROR” ) > 0 ]

This again does error checking, but this time it is checking the Messages::CurrentResult field (because the POP3it_Adv_GoToMessage was set to this field).

Perform Script [ " Disconnect" ]

If there is an error, the Disconnect script is called because at this point the plug-in is connected to the mail server, and you do not want to leave a connection open if you are not using it. Click on the Ok button to close the Check Email script, and then edit the Disconnect script.

Set Field [ Messages::Result; POP3it_Adv_Disconnect & “¶” & POP3it_StatusWindow( “Hide” ) & “¶” & Messages::Result

This script calls the POP3it_Adv_Disconnect function to disconnect from the mail server, closes the status window by passing the “Hide” parameter to the POP3it_StatusWindow function, and then appends the existing data from the Messages::Result field so it is not overwritten. Click on the Ok button to close the Disconnect script, and then edit the Check Email script again.

Show Custom Dialog [ Title: “Message”; Message: "There…] Go to Layout [ “Results” (Messages)] Exit Script [ ] End If

The user is then shown an error message, taken to the Results layout to see the error, and the script exits.

If [ Trim( Messages::CurrentResult) = 0 ]

This step checks to see if the Messages::CurrentResults contains a zero. The POP3it_Adv_GoToMessage function that was set to this field will return a zero if there are no new messages on the mail server. There is no reason to go through the download routine if there are no new messages to download.

Perform Script [ " Disconnect" ] Show Custom Dialog [ Title: “Message”; Message: "There…] Exit Script [ ] End If

If there are no messages, the Disconnect script is called, the user is informed, and the script exits.

Perform Script [ " Download Loop" ]

The download routine is started by calling the Download Loop script. Click on the Ok button to close the Check Email script, and then edit the Download Loop script.

Loop Set Field [ Messages::CurrentUIDL; POP3it_Adv_GetUniqueID ]

The script starts out by entering a loop and then setting the Messages::CurrentUIDL field with the current email’s UIDL as returned from the POP3it_Adv_GetUniqueID function. Each email in your email account has a unique ID which we use to see if the email already exists in the database.

If [ Count(Duplicate Check::UIDL) = 0 ]

This step uses a relationship and the Count function to see if the current email already exists in the database. The relationship is between the Messages::CurrentUIDL field and the Duplicate Check::UIDL field. If an email does not exist with the current UIDL, the relationship will be invaild and the Count function will return a zero, which will make this If statement true.

New Record/Request Perform Script [ " Get Current Email" ] End If

This will create a new record for the current email and call the Get Current Email script. Click on the Ok button to close the Download Loop script, and then edit the Get Current Email script.

Set Field [ Messages::UIDL; Messages::CurrentUIDL ]

The script starts out by setting the Messages::UIDL field for the current email from the Messages::CurrentUIDL field.

Set Field [ Messages::From; POP3it_Adv_GetHeader( “From” ) ] Set Field [ Messages::Subject; POP3it_Adv_GetHeader( “Subject” ) ]

The From address and Subject is then retrieved from the PPO3it_Adv_GetHeader function. This function will return different headers of an email depending on what parameter you pass to it.

Set Field [ Messages::MessageDate; POP3it_Adv_GetDate ]

The time and date of the email is then retrieved using the POP3it_Adv_GetDate function. This function returns a Timestamp, so Messages:MessageDate is a Timestamp type of field.

Set Field [ Messages::AccountName; Messages::CurrentAccount ]

Finally, the Messages::AccountName field is set with the account name as specified in the Messages::CurrentAccount field. This is done so we can go back and download the rest of the email later. If you had email in your database from different accounts and then wanted to go back and download the complete email later, you would not know what account to connect to if this data was not saved. This will be more apparent in the Download Individual Email script that will be coming up soon. If you wanted to download more of each email for your “preview”, you could add that here. Click on the Ok button to close the Get Current Email script, and then edit the Download Loop script again.

Set Field [ Messages::CurrentResult; POP3it_Adv_GoToMessage( “Next” ) ]

This step calls the POP3it_Adv_GoToMessage function to go to the next message on the mail server.

Exit Loop If [ Trim(Messages::CurrentResult) = “0” or PatternCount(Messages::CurrentResult;“ERROR” ) > 0 ] End Loop

When there are no more emails on the mail server the POP3it_Adv_GoToMessage function from the previous step will return a zero. This step checks to see if the Messages::CurrentResult field is zero, or if the function returned an error, and exits the loop. Click on the Ok button to close the Download Loop script, and then edit the Check Email script.

Perform Script [ " Disconnect" ] End If

The script is now done downloading email, so the Disconnect script is called to close the connection and status window. Click on the Ok button to close the Check Email script, and then edit the Download Individual Email script.

Set Field [ Messages::Result; POP3it_StatusWindow( “Show”) & “¶” & POP3it_Adv_Connect( Messages::AccountName) ]

This script downloads the remaining data for each email when called. The script starts by showing the status window and then connecting to the account as specified in the current record. As mentioned before, if we did not save what account the email came from and downloaded email from multiple accounts, it would not be possible to download the remaining data.

If [ PatternCount( Messages::Result; “ERROR”) > 0 ]

This step checks if there was an error from the POP3it_Adv_Connect function.

Show Custom Dialog [ Title: “Message”; Message: "There…] Set Field [ Messages::Result; POP3it_StatusWindow( “Hide” ) & “¶” & Messages::Result ] Exit Script [ ] End If

This step hides the status window, shows the user an error message, and exits the script.

Set Field [ Messages::CurrentResult; POP3it_Adv_GoToMessage( Messages::UIDL ) ]

This step “finds” the current email on the mail server. This is done with the POP3it_Adv_GoToMessage function by specifying the email’s ID (from the Messages::UIDL field) as the parameter. The plug-in is now ready to download the email data which is done in the next few steps after error checking.

If [ PatternCount( Messages::CurrentResult; “ERROR” ) > 0 ]

This again does error checking, but this time it is checking the Messages::CurrentResult field (because the POP3it_Adv_GoToMessage was set to this field).

Perform Script [ " Disconnect" ] Show Custom Dialog [ Title: “Message”; Message: "There…] Go to Layout [ “Results” (Messages) ] Exit Script [ ] End If

The script then disconnects using the Disconnect Script, shows the user an error, goes to the Results layout to display the error, and exits the script.

Set Field [ Messages::TextBody; POP3it_Adv_GetBody( “Text” ) ]

This step downloads the text body into the Messages::TextBody field using the POP3it_Adv_GetBody function with “Text” specified as the parameter.

Set Field [ Messages::HTMLBody; POP3it_Adv_GetBody( “HTML” ) ]

This step downloads the html body into the Messages::HTMLBody field using the POP3it_Adv_GetBody function with “HTML” specified as the parameter.

Set Field [ Messages::To; POP3it_Adv_GetHeader( “To” ) ]

This step downloads the To address into the Messages::To field using the POP3it_Adv_GetHeader function with “To” specified as the parameter.

Set Field [ Messages::Attachments; POP3it_Adv_SaveAttachment ]

This step downloads the attachments for the email into the folder specified in the current Account. The paths for the attachments are returned in the Messages::Attachments field.

Perform Script [" Disconnect"]

This step calls the Disconnect script which disconnects from the mail server and hides the status window.

Perform Script [" View Message"]

Finally, the View Message script is called which chooses the correct layout to display the email on. Click on the Ok button to close the Download Individual Email script, and then edit the Delete Individual Email script.

Show Custom Dialog [ Title: “Message”; Message: "Are you sure…]

This script allows you to delete the current email from the mail server and database. The first step confirms the user wants to delete the message by displaying a dialog.

If [ Get ( LastMessageChoice ) = 1 ]

This uses the FileMaker function Get ( LastMessageChoice ) to check what button was clicked on the previous dialog. If the OK button was clicked, this function will return a 1, which means the If statement will be true.

Set Field [ Messages::Result; POP3it_StatusWindow( “Show”) & “¶” & POP3it_Adv_Connect( Messages::AccountName) ]

This step shows the status window and connects to the account as specified in the Messages::Account Name field.

If [ PatternCount( Messages::Result; “ERROR”) > 0 ]

This step checks if there was an error from the POP3it_Adv_Connect function.

Show Custom Dialog [ Title: “Message”; Message: "There…] Set Field [ Messages::Result; POP3it_StatusWindow( “Hide” ) & “¶” & Messages::Result ] Exit Script [ ] End If

This step hides the status window, shows the user an error message, and exits the script.

Set Field [ Messages::CurrentResult; POP3it_Adv_GoToMessage( Messages::UIDL ) ]

This step “finds” the current email on the mail server. This is done with the POP3it_Adv_GoToMessage function by specifying the email’s ID (from the Messages::UIDL field) as the parameter. The plug-in is now ready to delete the email which is done in the next few steps after error checking.

If [ PatternCount( Messages::CurrentResult; “ERROR” ) > 0 ]

This again does error checking, but this time it is checking the Messages::CurrentResult field (because the POP3it_Adv_GoToMessage was set to this field).

Perform Script [ " Disconnect" ] Show Custom Dialog [ Title: “Message”; Message: "There…] Go to Layout [ “Results” (Messages) ] Exit Script [ ] End If

The script then disconnects using the Disconnect Script, shows the user an error, goes to the Results layout to display the error, and exits the script.

Set Field [ Messages::CurrentResult; POP3it_Adv_Delete ]

This step deletes the email from the mail server using the POP3it_Adv_Delete function.

If [ PatternCount( Messages::CurrentResult; “ERROR” ) > 0 ]

The script then checks if there was an error while attempting to delete the email from the mail server.

Perform Script [ " Disconnect" ] Show Custom Dialog [ Title: “Message”; Message: "There Go to Layout [ “Results” (Messages) ] Exit Script [ ] End If

If there was an error, the script calls the Disconnect script, shows the user an error, goes to the Results layout to display the error, and exits the script.

Delete Record/Request

The email has been deleted from the mail server so the record can now be deleted from the database.

Perform Script [ " Disconnect" ]

This step calls the Disconnect script which disconnects the plug-in from the mail server.

If [ Get ( LayoutName ) = “List” ] Perform Script [ “View Message” ] End If End If

This If statement checks to see if the current layout is named “List”. This was done because when a record is deleted from the database, a new record will become the “current” record. If the current layout is a detail layout, the script needs to choose the correct layout to display the new current record on. The layout is chosen by the View Message Script.