Count Messages with Email Connector
Anypoint Connector for Email (Email Connector) provides the Count messages - IMAP and Count messages - POP3 operations, which get the total amount of messages in a specified mailbox folder.
Configure Count Messages - IMAP Operation
The following example shows how to configure the Count messages - IMAP operation:
- 
Create a new Mule project in Studio.
 - 
Drag an HTTP Listener source to the canvas.
 - 
On the Listener configuration screen, click the plus sign (+) next to the Connector configuration field to configure a global element for the operation.
 - 
Configure the required HTTP Listener connection fields and click OK.
 - 
Set Path to
/count. - 
Drag the Count messages - IMAP operation to the right of HTTP Listener.
 - 
On the Count messages - IMAP configuration screen, click the plus sign (+) next to the Connector configuration field to configure a global element for the operation.
 - 
Set the following fields:
- 
Host:
192.168.0.1 - 
User:
usertest - 
Host:
userpass 
 - 
 - 
Click OK.
 - 
For Mailbox folder, click fx to switch to literal mode and set it to
vars.mailboxFolder. - 
Set Count filter to any of the following options:
- 
ALL (Default)
 - 
DELETED
 - 
NEW
 - 
UNREAD
 
 - 
 
In the Configuration XML editor, the email:count-messages-imap configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"
	xmlns:email="http://www.mulesoft.org/schema/mule/email"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
	<email:imap-config name="Email_IMAP"  >
		<email:imap-connection host="192.168.0.1" user="usertest" password="userpass" />
	</email:imap-config>
	<http:listener-config name="HTTP_Listener_config" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<flow name="email1Flow"  >
		<http:listener config-ref="HTTP_Listener_config" path="/count"/>
		<email:count-messages-imap doc:name="Count messages - IMAP" config-ref="Email_IMAP" mailboxFolder="#[vars.mailboxFolder]" countFilter="NEW"/>
	</flow>
</mule>
Configure Count Messages - POP3 Operation
The following example shows how to configure the Count messages - POP3 operation:
- 
Create a new Mule project in Studio.
 - 
Drag an HTTP Listener source to the canvas.
 - 
On the Listener configuration screen, click the plus sign (+) next to the Connector configuration field to configure a global element for the operation.
 - 
Configure the required HTTP Listener connection fields and click OK.
 - 
Set Path to
/count. - 
Drag the Count messages - POP3 operation to the right of HTTP Listener.
 - 
On the Count messages - POP3 configuration screen, click the plus sign (+) next to the Connector configuration field to configure a global element for the operation.
 - 
Set the following fields:
- 
Host:
192.168.0.1 - 
User:
usertest - 
Host:
userpass 
 - 
 
In the Configuration XML editor, the email:count-messages-pop3 configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:file="http://www.mulesoft.org/schema/mule/file"
	xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
	<http:listener-config >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<email:pop3-config name="Email_POP3" >
		<email:pop3-connection host="192.168.0.1" user="usertest" password="userpass" />
	</email:pop3-config>
	<flow name="email1Flow" >
		<http:listener config-ref="HTTP_Listener_config" path="/count"/>
		<email:count-messages-pop3 doc:name="Count messages - POP3" config-ref="Email_POP3"/>
	</flow>
</mule>



