The Email Receive task allows you to receive POP3 email data into a SQL Server Integration Services control flow.
Messages can be processed synchronously by waiting for the component to finish
blocking on receipt of a message, or asynchronously by handling the
OnReceiveMessage event.
This task is easily configured by dragging an instance onto the control flow surface and double-clicking. The following form is presented :
You simply create or select a POP3 Connection (which involves supplying details of the server name or address and login details), and define how to capture the data from the email. There are various options, you can either capture the entire body text, the contents of the first attachment, or the body text after a delimiter string. The data is then saved to a specified variable. Separately you can also capture details of the email sender, subject and body text to variables.
The
Delete Email option allows you to determine when the email, having been read, will be deleted. If
Immediately is selected, the email will be deleted as soon as it has been retrieved. This is potentially problematic, as it creates a windows where an email can be received into a variable and deleted but subsequent processing may fail. To get around this issue you can select
On Transaction Scope Commit, whereupon the email will only be deleted when the containing SSIS transaction commits. However there is a restriction in that you cannot receive a second email from the component inside the same transaction scope.
The Timeouts tab enables you to configure how long your component will wait to
receive an email message. There are two modes of operation - synchronous and asynchronous. In
synchronous mode the task effectively blocks until a file is received, whereupon
it completes and linked tasks can execute. In asynchronous mode you would
typically handle the
OnReceiveMessage event
exposed by the component to handle messages as they arrive. This event has
no parameters, as the received message is already bound to a variable.
The
Delay between poll attempts field allows you to configure the number
of seconds between successive checks on the messaging database to determine if
any matching messages have arrived. The
Get timeout field is the
total number of seconds for the component to wait for a message to arrive before
giving up. The
Fail task on Get timeout option allows you to
determine if such a state should trigger a failure of the component.
Otherwise you can check if a file was retrieved by checking the Message variable
(which will have empty content if no message was retrieved) or using the
ExecValueVariable result.
0 and -1 are special cases for
Get timeout, relating to a zero or
infinite timeout respectively. In the case of a zero timeout, this means
that the component will not wait if there is no message waiting in the messaging
database.
Note that you can also execute this task within a Foreach Loop Container task, to execute the contained tasks once for every file retrieved. Simply select 'BlueSSIS +Email Message Enumerator' as the Enumerator, then click the 'Configure...' button to configure the properties.
BlueSSIS provides a number of enumerators, mostly mapping to associated data retrieval tasks, but also including an Infinite Loop enumerator (useful for manual polling scenarios), and a Loop Once enumerator, useful if you want to use the ForEach Loop Container task as a transaction scope.