Schedule a recurring task to import POP3 content
Overview
Monthly email newsletters are a tool for informing customers about your products and services. This information includes the latest product updates, new promotions, new tools, and upcoming corporate events. To stay informed, many organizations subscribe to competitor’s email newsletters to monitor their announcements and the quality of their marketing materials. These materials circulate internally and are used for strategic planning.
Sitefinity CMS can help you gather, aggregate, and publish this content to your Intranet. This tutorial guides you through the steps required to create a scheduled task that updates your feed automatically. For more information about feeds in Sitefinity CMS, see Feeds.
Subscribing
Using the Sitefinity CMS publishing system, you can consume external RSS and Atom feeds as well as mail content using the POP3 protocol. Once consumed, this data can be blended into a Publishing Point (data mashup) and published on your Intranet portal.
Once you aggregate the necessary information, you can choose either to publish this content in your Sitefinity CMS project as news, blogs, and events or push it directly to Twitter or RSS.
Create the feed
You can use the Sitefinity CMS publishing system to pull e-mails from a POP3 email account.
To create a feed, set up a new POP3 import, and configure its display in your website, perform the following:
Create a feed
- Go to Sitefinity CMS backend.
- In the main menu, choose Administration » Alternative Publishing.
- On the Feeds & Notifications page, click Create a Feed.
The Create a feed panel opens.
- In the Title field, enter Competitors Newsletters.
Configure the POP3 server
In the Content to include section you define the content that goes to the Sitefinity CMS publishing point. It can be content from your Sitefinity CMS website or an external ATOM, RSS, or POP3 feed. To configure the feed to pull information from POP3, do the following:
-
Click Add another content type.
The Select content source panel opens.
- Select the option Mail Content.
- In the POP3 server field, enter your preferred mail server, typically pop.gmail.com.
- In the Port field, enter 995.
- Choose whether to use SSL connection.
If you use Gmail, you must select this checkbox.
- In the Account field, enter an appropriate administrative email and password. For example, my-sample-Sitefinity-watch@gmail.com.
- If you need to do special mappings, click Mapping Settings, and then enter appropriate data in the New publishing point: Pop3InboundPipe dialog.
- Select the preferred Schedule publication updates interval.
NOTE: In the dialog box above, the following message is displayed - All successfully retrieved mail messages will be deleted from the POP3 server. Refer to the documentation of your mail server since this is subject to configuration. For example, Gmail allows you to leave a copy of the retrieved messages in your inbox, so that you do not lose any of your emails. For more information, see Gmail POP3 configuration settings.
Configure how the feed appears on Sitefinity CMS website
In the Publish as section, you configure how this information will be displayed on your Sitefinity CMS website. To configure the publishing of the retrieved content, do the following:
- In Publish as section, click Add more...
- Select Sitefinity content.
- In Import data as dropdown box select News items.
- Select Automatically publish imported data.
- If you need to do special mappings, click Mapping Settings, and then enter appropriate data in the New publishing point: Pop3InboundPipe dialog.
- Click Done.
- Click Save changes to save your information and create the feed.
Create the task
To create a task, perform the following:
- Open your Sitefinity CMS project in Visual Studio.
- From the context menu of the project, click Add » New Item...
- In the left pane, select Visual C# » Code.
- ClickClass.
- In the Name input field, enter PipeScheduledTask.cs.
- Open the newly created file.
- Add the following code:
In the code above, ExecuteTask
method you get the feed from the publishing system and execute it. You must also set the TaskName
to reflect the full class name so that the system can properly instantiate the task from the factory and execute it at a specified point. Once the task is executed you must invoke the scheduling manager and queue a new task of the same type.
Schedule the task
To schedule your task as early in the application lifecycle as possible, you must handle the Initialized
event of the Bootstrapper
inside the Application_Start
handler of your application. Perform the following:
- Open your Sitefinity web app in Visual Studio.
- From the context menu of the project, click Add » New Item...
- In the left pane, select Visual C# » Web.
- Click Global Application Class.
- Keep the default name
Global.asax
.
- Open the newly created file.
- Add the following code:
The Global.asax
file is used to handle application and session-state events in the ASP.NET website.
You create a key for the task so you can search for it later. The Key
property of PipeScheduledTask
is a string. You must set the ExecuteTime
property of the tasks that determines when this task is going to be executed.
NOTE: You must set all date and time values in a UTC format in Sitefinity CMS.
Once you queue the tasks and commit the transaction, Sitefinity CMS determines when it must execute the tasks. If it finds a task that is not yet executed and its execution time has already passed, Sitefinity CMS automatically executes and deletes it.