Skip to main content

email (Sink)

The email sink uses the smtp server to publish events via emails. The events can be published in text, xml or json formats. The user can define email sink parameters in either the \<SP_HOME>/conf/<PROFILE>/deployment yaml file or in the stream definition. The email sink first checks the stream definition for parameters, and if they are no configured there, it checks the deployment.yaml file. If the parameters are not configured in either place, default values are considered for optional parameters. If you need to configure server system parameters that are not provided as options in the stream definition, then those parameters need to be defined them in the deployment.yaml file under email sink properties. For more information about the SMTP server parameters, see https://javaee.github.io/javamail/SMTP-Transport. Some email accounts require the access to less secure apps option. For GMail accounts, you can enable this option via https://myaccount.google.com/lesssecureapps.

Syntax

CREATE SINK <NAME> WITH (type="email", map.type="<STRING>", username="<STRING>", address="<STRING>", password="<STRING>", host="<STRING>", port="<INT>", ssl.enable="<BOOL>", auth="<BOOL>", content.type="<STRING>", subject="<STRING>", to="<STRING>", cc="<STRING>", bcc="<STRING>", attachments="<STRING>", connection.pool.size="<INT>")

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
usernameThe username of the email account that is used to send emails. e.g., abc is the username of the abc@gmail.com account.STRINGNoNo
addressThe address of the email account that is used to send emails.STRINGNoNo
passwordThe password of the email account.STRINGNoNo
hostThe host name of the SMTP server. e.g., smtp.gmail.com is a host name for a gmail account. The default value smtp.gmail.com is only valid if the email account is a gmail account.smtp.gmail.comSTRINGYesNo
portThe port that is used to create the connection.465 the default value is only valid is SSL is enabled.INTYesNo
ssl.enableThis parameter specifies whether the connection should be established via a secure connection or not. The value can be either true or false. If it is true, then the connection is establish via the 493 port which is a secure connection.trueBOOLYesNo
authThis parameter specifies whether to use the AUTH command when authenticating or not. If the parameter is set to true, an attempt is made to authenticate the user using the AUTH command.trueBOOLYesNo
content.typeThe content type can be either text/plain or text/html.text/plainSTRINGYesNo
subjectThe subject of the mail to be send.STRINGNoYes
toThe address of the to recipient. If there are more than one to recipients, then all the required addresses can be given as a comma-separated list.STRINGNoYes
ccThe address of the cc recipient. If there are more than one cc recipients, then all the required addresses can be given as a comma-separated list.NoneSTRINGYesNo
bccThe address of the bcc recipient. If there are more than one bcc recipients, then all the required addresses can be given as a comma-separated list.NoneSTRINGYesNo
attachmentsFile paths of the files that need to be attached to the email. These paths should be absolute paths. They can be either directories or files . If the path is to a directory, all the files located at the first level (i.e., not within another sub directory) are attached.NoneSTRINGYesYes
connection.pool.sizeNumber of concurrent Email client connections.1INTYesNo

System Parameters

NameDescriptionDefault ValuePossible Parameters
mail.smtp.ssl.trustIf this parameter is se, 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 it is set to a whitespace-separated list of hosts, only those specified hosts are trusted. If not, the hosts trusted depends on the certificate presented by the server.*String
mail.smtp.connectiontimeoutThe socket connection timeout value in milliseconds.infinite timeoutAny Integer
mail.smtp.timeoutThe socket I/O timeout value in milliseconds.infinite timeoutAny Integer
mail.smtp.fromThe email address to use for the SMTP MAIL command. This sets the envelope return address.Defaults to msg.getFrom() or InternetAddress.getLocalAddress().Any valid email address
mail.smtp.localportThe local port number to bind to when creating the SMTP socket.Defaults to the port number picked by the Socket class.Any Integer
mail.smtp.ehloIf this parameter is set to false, you must not attempt to sign in with the EHLO command.truetrue or false
mail.smtp.auth.login.disableIf this is set to true, it is not allowed to use the AUTH LOGIN command.falsetrue or false
mail.smtp.auth.plain.disableIf this parameter is set to true, it is not allowed to use the AUTH PLAIN command.falsetrue or false
mail.smtp.auth.digest-md5.disableIf this parameter is set to true, it is not allowed to use the AUTH DIGEST-MD5 command.falsetrue or false
mail.smtp.auth.ntlm.disableIf this parameter is set to true, it is not allowed to use the AUTH NTLM commandfalsetrue or false
mail.smtp.auth.ntlm.domainThe NTLM authentication domain.NoneThe valid NTLM authentication domain name.
mail.smtp.auth.ntlm.flagsNTLM protocol-specific flags. For more details, see http://curl.haxx.se/rfc/ntlm.html\#theNtlmFlags.NoneValid NTLM protocol-specific flags.
mail.smtp.dsn.notifyThe NOTIFY option to the RCPT command.NoneEither NEVER, or a combination of SUCCESS, FAILURE, and DELAY (separated by commas).
mail.smtp.dsn.retThe RET option to the MAIL command.NoneEither FULL or HDRS.
mail.smtp.sendpartialIf this parameter is set to true and a message is addressed to both valid and invalid addresses, the message is sent with a log that reports the partial failure with a SendFailedException error. If this parameter is set to false (which is default), the message is not sent to any of the recipients when the recipient lists contain one or more invalid addresses.falsetrue or false
mail.smtp.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.smtp.sasl.mechanismsEnter a space or a comma-separated list of SASL mechanism names that the system shouldt try to use.None
mail.smtp.sasl.authorizationidThe authorization ID to be used in the SASL authentication. If no value is specified, the authentication ID (i.e., username) is used.usernameValid ID
mail.smtp.sasl.realmThe realm to be used with the DIGEST-MD5 authentication.None
mail.smtp.quitwaitIf this parameter is set to false, the QUIT command is issued and the connection is immediately closed. If this parameter is set to true (which is default), the transport waits for the response to the QUIT command.falsetrue or false
mail.smtp.reportsuccessIf this parameter is set to true, the transport to includes an SMTPAddressSucceededException for each address to which the message is successfully delivered.falsetrue or false
mail.smtp.socketFactoryIf this parameter is set to a class that implements the javax.net.SocketFactory interface, this class is used to create SMTP sockets.NoneSocket Factory
mail.smtp.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 SMTP sockets.None
mail.smtp.socketFactory.fallbackIf this parameter is set to true, the failure to create a socket using the specified socket factory class causes the socket to be created using the java.net.Socket class.truetrue or false
mail.smtp.socketFactory.portThis specifies the port to connect to when using the specified socket factory.25Valid port number
mail.smtp.ssl.protocolsThis specifies the SSL protocols that need to be enabled for the SSL connections.NoneThis parameter specifies a whitespace separated list of tokens that are acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.
mail.smtp.starttls.enableIf this parameter is set to true, it is possible to issue 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.smtp.starttls.requiredIf this parameter is set to true, it is required to use the STARTTLS command. If the server does not support the STARTTLS command, or if the command fails, the connection method will fail.falsetrue or false
mail.smtp.socks.hostThis specifies the host name of a SOCKS5 proxy server to be used for the connections to the mail server.None
mail.smtp.socks.portThis specifies the port number for the SOCKS5 proxy server. This needs to be used only if the proxy server is not using the standard port number 1080.1080valid port number
mail.smtp.auth.ntlm.disableIf this parameter is set to true, the AUTH NTLM command cannot be issued.falsetrue or false
mail.smtp.mailextensionThe extension string to be appended to the MAIL command.None
mail.smtp.usersetIf this parameter is set to true, you should use the RSET command instead of the NOOP command in the isConnected method. In some scenarios, sendmail responds slowly after many NOOP commands. This is avoided by using RSET instead.falsetrue or false

Example 1

CREATE SINK FooStream WITH (type='email', map.type ='json', username='sender.account', address='sender.account@gmail.com',password='account.password',subject='Alerts from gdn Stream Processor',to='{{email}}') (email string, loginId int, name string);

This example illustrates how to publish events via an email sink based on the values provided for the mandatory parameters. As shown in the example, it publishes events from the FooStream in json format as emails to the specified to recipients via the email sink. The email is sent from the sender.account@gmail.com email address via a secure connection.

Example 2

CREATE SINK FooStream WITH type='email', map.type ='json', subject='Alerts from gdn Stream Processor',to='{{email}}') (email string, loginId int, name string);

This example illustrates how to configure the ## Query Parameters and the system parameters in the deployment.yaml file.

As shown in the example, events from the FooStream are published in json format via the email sink as emails to the given to recipients. The email is sent from the sender.account@gmail.com address via a secure connection.

Example 3

CREATE SINK FooStream WITH (type='email', map.type ='json', username='sender.account', address='sender.account@gmail.com',password='account.password',host='smtp.gmail.com',port='465',ssl.enable='true',auth='true',content.type='text/html',subject='Alerts from gdn Stream Processor-{{name}}',to='to1.account@gmail.com, to2.account@gmail.com',cc='cc1.account@gmail.com, cc2.account@gmail.com',bcc='bcc1.account@gmail.com) (name string, age int, country string);

This example illustrates how to publish events via the email sink. Events from the FooStream stream are published in xml format via the email sink as a text/html message and sent to the specified to, cc, and bcc recipients via a secure connection. The name namespace in the subject attribute is the value of the name parameter in the corresponding output event.

Example 4

CREATE SINK FooStream WITH (type='email', map.type ='json', username='sender.account', address='sender.account@gmail.com',password='account.password',host='smtp.gmail.com',port='465',ssl.enable='true',auth='true',content.type='text/html',subject='Alerts from gdn Stream Processor-{{name}}',to='to1.account@gmail.com, to2.account@gmail.com',cc='cc1.account@gmail.com, cc2.account@gmail.com',bcc='bcc1.account@gmail.comattachments= '{{attachments}}') (name string, age int, country string, attachments string);

This example illustrates how to publish events via the email sink. Here, the email also contains attachments. Events from the FooStream are published in xml format via the email sink as a text/html message to the specified to,cc, and bcc recipients via a secure connection. The name namespace in the subject attribute is the value for the name parameter in the corresponding output event. The attachments included in the email message are the local files available in the path specified as the value for the attachments attribute.