Skip to main content

email (Source)

The Email source allows you to receive events via emails. An Email source can be configured using the imap or pop3 server to receive events. This allows you to filter the messages that satisfy the criteria specified under the search term option. The email source parameters can be defined in either the <SP_HOME>/conf/<PROFILE>/deployment yaml file or the stream definition. If the parameter configurations are not available in either place, the default values are considered (i.e., if default values are available). If you need to configure server system parameters that are not provided as options in the stream definition, they need to be defined in the deployment yaml file under email source properties. For more information about imap and pop3 server system parameters, see the following. [JavaMail Reference Implementation - IMAP Store](https://javaee.github.io/javamail/IMAP-Store) [JavaMail Reference Implementation - POP3 Store Store](https://javaee.github.io/javamail/POP3-Store)

Syntax

CREATE SOURCE <NAME> WITH (type="email", map.type="<STRING>", username="<STRING>", password="<STRING>", store="<STRING>", host="<STRING>", port="<INT>", folder="<STRING>", search.term="<STRING>", polling.interval="<LONG>", action.after.processed="<STRING>", folder.to.move="<STRING>", content.type="<STRING>", ssl.enable="<BOOL>")

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
usernameThe user name of the email account. e.g., gdnmail is the username of the gdnmail@gmail.com mail account.STRINGNoNo
passwordThe password of the email accountSTRINGNoNo
storeThe store type that used to receive emails. Possible values are imap and pop3.imapSTRINGYesNo
hostThe host name of the server (e.g., imap.gmail.com is the host name for a gmail account with an IMAP store.). The default value imap.gmail.com is only valid if the email account is a gmail account with IMAP enabled.If store type is imap, then the default value is imap.gmail.com. If the store type is pop3, then the default value is pop3.gmail.com.STRINGYesNo
portThe port that is used to create the connection.993, the default value is valid only if the store is imap and ssl-enabled.INTYesNo
folderThe name of the folder to which the emails should be fetched.INBOXSTRINGYesNo
search.termThe option that includes conditions such as key-value pairs to search for emails. In a string search term, the key and the value should be separated by a semicolon (;). Each key-value pair must be within inverted commas ( ). The string search term can define multiple comma-separated key-value pairs. This string search term currently supports only the subject, from, to, bcc, and cc keys. e.g., if you enter subject:DAS, from:carbon, bcc:gdn, the search term creates a search term instance that filters emails that contain DAS in the subject, carbon in the from address, and gdn in one of the bcc addresses. The string search term carries out sub string matching that is case-sensitive. If @ in included in the value for any key other than the subject key, it checks for an address that is equal to the value given. e.g., If you search for abc@, the string search terms looks for an address that contains abc before the @ symbol.NoneSTRINGYesNo
polling.intervalThis defines the time interval in seconds at which th email source should poll the account to check for new mail arrivals.in seconds.600LONGYesNo
action.after.processedThe action to be performed by the email source for the processed mail. Possible values are as follows: FLAGGED: Sets the flag as flagged. SEEN: Sets the flag as read. ANSWERED: Sets the flag as answered. DELETE: Deletes tha mail after the polling cycle. MOVE: Moves the mail to the folder specified in the folder.to.move parameter. If the folder specified is pop3, then the only option available is DELETE.NONESTRINGYesNo
folder.to.moveThe name of the folder to which the mail must be moved once it is processed. If the action after processing is MOVE, it is required to specify a value for this parameter.STRINGNoNo
content.typeThe content type of the email. It can be either text/plain or text/html.text/plainSTRINGYesNo
ssl.enableIf this is set to true, a secure port is used to establish the connection. The possible values are true and false.trueBOOLYesNo

System Parameters

NameDescriptionDefault ValuePossible Parameters
mail.imap.partialfetchThis determines whether the IMAP partial-fetch capability should be used.truetrue or false
mail.imap.fetchsizeThe partial fetch size in bytes.16Kvalue in bytes
mail.imap.peekIf this is set to true, the IMAP PEEK option should be used when fetching body parts to avoid setting the SEEN flag on messages. The default value is false. This can be overridden on a per-message basis by the setPeek method in IMAPMessage.falsetrue or false
mail.imap.connectiontimeoutThe socket connection timeout value in milliseconds. This timeout is implemented by java.net.Socket.infinity timeoutAny Integer value
mail.imap.timeoutThe socket read timeout value in milliseconds. This timeout is implemented by java.net.Socket.infinity timeoutAny Integer value
mail.imap.writetimeoutThe socket write timeout value in milliseconds. This timeout is implemented by using a java.util.concurrent.ScheduledExecutorService per connection that schedules a thread to close the socket if the timeout period elapses. Therefore, the overhead of using this timeout is one thread per connection.infinity timeoutAny Integer value
mail.imap.statuscachetimeoutThe timeout value in milliseconds for the cache of STATUS command response.1000msTime out in miliseconds
mail.imap.appendbuffersizeThe maximum size of a message to buffer in memory when appending to an IMAP folder.NoneAny Integer value
mail.imap.connectionpoolsizeThe maximum number of available connections in the connection pool.1Any Integer value
mail.imap.connectionpooltimeoutThe timeout value in milliseconds for connection pool connections.45000msAny Integer
mail.imap.separatestoreconnectionIf this parameter is set to true, it indicates that a dedicated store connection needs to be used for store commands.truetrue or false
mail.imap.auth.login.disableIf this is set to true, it is not possible to use the non-standard AUTHENTICATE LOGIN command instead of the plain LOGIN command.falsetrue or false
mail.imap.auth.plain.disableIf this is set to true, the AUTHENTICATE PLAIN command cannot be used.falsetrue or false
mail.imap.auth.ntlm.disableIf true, prevents use of the AUTHENTICATE NTLM command.falsetrue or false
mail.imap.proxyauth.userIf the server supports the PROXYAUTH extension, this property specifies the name of the user to act as. Authentication to log in to the server is carried out using the administrator's credentials. After authentication, the IMAP provider issues the PROXYAUTH command with the user name specified in this property.NoneValid string value
mail.imap.localaddressThe local address (host name) to bind to when creating the IMAP socket.Defaults to the address picked by the Socket class.Valid string value
mail.imap.localportThe local port number to bind to when creating the IMAP socket.Defaults to the port number picked by the Socket class.Valid String value
mail.imap.sasl.enableIf this parameter is set to true, the system attempts to use the javax.security.sasl package to choose an authentication mechanism for the login.falsetrue or false
mail.imap.sasl.mechanismsA list of SASL mechanism names that the system should to try to use. The names can be separated by spaces or commas.NoneValid string value
mail.imap.sasl.authorizationidThe authorization ID to use in the SASL authentication.If this parameter is not set, the authentication ID (username) is used.Valid string value
mail.imap.sasl.realmThe realm to use with SASL authentication mechanisms that require a realm, such as DIGEST-MD5.NoneValid string value
mail.imap.auth.ntlm.domainThe NTLM authentication domain.NoneValid string value
The NTLM authentication domain.NTLM protocol-specific flags.NoneValid integer value
mail.imap.socketFactoryIf this parameter is set to a class that implements the javax.net.SocketFactory interface, this class is used to create IMAP sockets.NoneValid SocketFactory
mail.imap.socketFactory.classIf this parameter is set, it specifies the name of a class that implements the javax.net.SocketFactory interface. This class is used to create IMAP sockets.NoneValid string
mail.imap.socketFactory.fallbackIf this parameter is set to true, failure to create a socket using the specified socket factory class results in the socket being created using the java.net.Socket class.truetrue or false
mail.imap.socketFactory.portThis specifies the port to connect to when using the specified socket factory. If this parameter is not set, the default port is used.143Valid Integer
mail.imap.ssl.checkserveridentityIf this parameter is set to true, the system checks the server identity as specified by RFC 2595.falsetrue or false
mail.imap.ssl.trustIf this parameter is set and a socket factory has not been specified, it enables the use of a MailSSLSocketFactory. If this parameter is set to *, all the hosts are trusted. If this parameter specifies list of hosts separated by white spaces, only those hosts are trusted. If the parameter is not set to any of the values mentioned above, trust depends on the certificate presented by the server.*Valid String
mail.imap.ssl.socketFactoryIf this parameter is set to a class that extends the javax.net.ssl.SSLSocketFactory class this class is used to create IMAP SSL sockets.NoneSSL Socket Factory
mail.imap.ssl.socketFactory.classIf this parameter is set, it specifies the name of a class that extends the javax.net.ssl.SSLSocketFactory class. This class is used to create IMAP SSL sockets.NoneValid String
mail.imap.ssl.socketFactory.portThis specifies the port to connect to when using the specified socket factory.the default port 993 is used.valid port number
mail.imap.ssl.protocolsThis specifies the SSL protocols that are enabled for SSL connections. The property value is a whitespace-separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.NoneValid string
mail.imap.starttls.enableIf this parameter is set to true, it is possible to use the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands.falsetrue or false
mail.imap.socks.hostThis specifies the host name of a SOCKS5 proxy server that is used to connect to the mail server.NoneValid String
mail.imap.socks.portThis specifies the port number for the SOCKS5 proxy server. This is needed if the proxy server is not using the standard port number 1080.1080Valid String
mail.imap.minidletimeThis property sets the delay in milliseconds.10 millisecondstime in seconds (Integer)
mail.imap.enableimapeventsIf this property is set to true, it enables special IMAP-specific events to be delivered to the ConnectionListener of the store. The unsolicited responses received during the idle method of the store are sent as connection events with IMAPStore.RESPONSE as the type. The event's message is the raw IMAP response string.falsetrue or false
mail.imap.folder.classThe class name of a subclass of com.sun.mail.imap.IMAPFolder. The subclass can be used to provide support for additional IMAP commands. The subclass must have public constructors of the form public MyIMAPFolder(String fullName, char separator, IMAPStore store, Boolean isNamespace) and public MyIMAPFolder(ListInfo li, IMAPStore store)NoneValid String
mail.pop3.connectiontimeoutThe socket connection timeout value in milliseconds.Infinite timeoutInteger value
mail.pop3.timeoutThe socket I/O timeout value in milliseconds.Infinite timeoutInteger value
mail.pop3.message.classThe class name of a subclass of com.sun.mail.pop3.POP3Message.NoneValid String
mail.pop3.localaddressThe local address (host name) to bind to when creating the POP3 socket.Defaults to the address picked by the Socket class.Valid String
mail.pop3.localportThe local port number to bind to when creating the POP3 socket.Defaults to the port number picked by the Socket class.Valid port number
mail.pop3.apop.enableIf this parameter is set to true, use APOP instead of USER/PASS to log in to the POP3 server (if the POP3 server supports APOP). APOP sends a digest of the password instead of clearing the text password.falsetrue or false
mail.pop3.socketFactoryIf this parameter is set to a class that implements the javax.net.SocketFactory interface, this class is used to create POP3 sockets.NoneSocket Factory
mail.pop3.socketFactory.classIf this parameter is set, it specifies the name of a class that implements the javax.net.SocketFactory interface. This class is used to create POP3 sockets.NoneValid String
mail.pop3.socketFactory.fallbackIf this parameter is set to true, failure to create a socket using the specified socket factory class results in the socket being created using the java.net.Socket class.falsetrue or false
mail.pop3.socketFactory.portThis specifies the port to connect to when using the specified socket factory.Default portValid port number
mail.pop3.ssl.checkserveridentityIf this parameter is set to true, check the server identity as specified by RFC 2595.falsetrue or false
mail.pop3.ssl.trustIf this parameter is set and a socket factory has not been specified, it is possible to use a MailSSLSocketFactory. If this parameter is set to *, all the hosts are trusted. If the parameter is set to a whitespace-separated list of hosts, only those hosts are trusted. If the parameter is not set to any of the values mentioned above, trust depends on the certificate presented by the server.*Valid String
mail.pop3.ssl.socketFactoryIf this parameter is set to a class that extends the javax.net.ssl.SSLSocketFactory class, this class is used to create POP3 SSL sockets.NoneSSL Socket Factory
mail.pop3.ssl.checkserveridentityIf this parameter is set to true, the system checks the server identity as specified by RFC 2595.falsetrue or false
mail.pop3.ssl.trustIf this parameter is set and a socket factory has not been specified, it is possible to use a MailSSLSocketFactory. If this parameter is set to *, all the hosts are trusted. If the parameter is set to a whitespace-separated list of hosts, only those hosts are trusted.Trust depends on the certificate presented by the server.Valid String
mail.pop3.ssl.socketFactoryIf this parameter is set to a class that extends the javax.net.ssl.SSLSocketFactory class, this class is used to create POP3 SSL sockets.NoneSSL Socket Factory
mail.pop3.ssl.socketFactory.classIf this parameter is set, it specifies the name of a class that extends the javax.net.ssl.SSLSocketFactory class. This class is used to create POP3 SSL sockets.NoneValid String
mail.pop3.ssl.socketFactory.pThis parameter pecifies the port to connect to when using the specified socket factory.995Valid Integer
mail.pop3.ssl.protocolsThis parameter specifies the SSL protocols that are enabled for SSL connections. The property value is a whitespace-separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.NoneValid String
mail.pop3.starttls.enableIf this parameter is set to true, it is possible to use the STLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands.falsetrue or false
mail.pop3.starttls.requiredIf this parameter is set to true, it is required to use the STLS command. The connect method fails if the server does not support the STLS command or if the command fails.falsetrue or false
mail.pop3.socks.hostThis parameter specifies the host name of a SOCKS5 proxy server that can be used to connect to the mail server.NoneValid String
mail.pop3.socks.portThis parameter specifies the port number for the SOCKS5 proxy server.NoneValid String
mail.pop3.disabletopIf this parameter is set to true, the POP3 TOP command is not used to fetch message headers.falsetrue or false
mail.pop3.forgettopheadersIf this parameter is set to true, the headers that might have been retrieved using the POP3 TOP command is forgotten and replaced by the headers retrieved when the POP3 RETR command is executed.falsetrue or false
mail.pop3.filecache.enableIf this parameter is set to true, the POP3 provider caches message data in a temporary file instead of caching them in memory. Messages are only added to the cache when accessing the message content. Message headers are always cached in memory (on demand). The file cache is removed when the folder is closed or the JVM terminates.falsetrue or false
mail.pop3.filecache.dirIf the file cache is enabled, this property is used to override the default directory used by the JDK for temporary files.NoneValid String
mail.pop3.cachewritetoThis parameter controls the behavior of the writeTo method on a POP3 message object. If the parameter is set to true, the message content has not been cached yet, and the ignoreList is null, the message is cached before being written. If not, the message is streamed directly to the output stream without being cached.falsetrue or false
mail.pop3.keepmessagecontentIf this property is set to true, a hard reference to the cached content is retained, preventing the memory from being reused until the folder is closed, or until the cached content is explicitly invalidated (using the invalidate method).falsetrue or false

Example 1

CREATE SOURCE inputStream WITH (type='email', map.type='xml', username='receiver.account', password='account.password') (name string, age int, country string);

This example illustrates how to receive events in xml format via the email source. In this example, only the required parameters are defined in the stream definition. The default values are taken for the other parameters. The search term is not defined, and therefore, all the new messages in the inbox folder are polled and taken.

Example 2

CREATE SOURCE inputStream WITH (type='email', map.type='xml', username='receiver.account', password='account.password',store = 'imap',host = 'imap.gmail.com',port = '993',searchTerm = 'subject:Stream Processor, from: from.account@ , cc: cc.account',polling.interval='500',action.after.processed='DELETE',content.type='text/html') (name string, age int, country string);

This example illustrates how to receive events in xml format via the email source. The email source polls the mail account every 500 seconds to check whether any new mails have arrived. It processes new mails only if they satisfy the conditions specified for the email search term (the value for from of the email message should be from.account@.<host name>, and the message should contain cc.account in the cc receipient list and the word Stream Processor in the mail subject). in this example, the action after processing is DELETE. Therefore,after processing the event, corresponding mail is deleted from the mail folder.