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
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
username | The username of the email account that is used to send emails. e.g., abc is the username of the abc@gmail.com account. | STRING | No | No | |
address | The address of the email account that is used to send emails. | STRING | No | No | |
password | The password of the email account. | STRING | No | No | |
host | The 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.com | STRING | Yes | No |
port | The port that is used to create the connection. | 465 the default value is only valid is SSL is enabled. | INT | Yes | No |
ssl.enable | This 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. | true | BOOL | Yes | No |
auth | This 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. | true | BOOL | Yes | No |
content.type | The content type can be either text/plain or text/html . | text/plain | STRING | Yes | No |
subject | The subject of the mail to be send. | STRING | No | Yes | |
to | The 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. | STRING | No | Yes | |
cc | The 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. | None | STRING | Yes | No |
bcc | The 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. | None | STRING | Yes | No |
attachments | File 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. | None | STRING | Yes | Yes |
connection.pool.size | Number of concurrent Email client connections. | 1 | INT | Yes | No |
System Parameters
Name | Description | Default Value | Possible Parameters |
---|---|---|---|
mail.smtp.ssl.trust | If 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.connectiontimeout | The socket connection timeout value in milliseconds. | infinite timeout | Any Integer |
mail.smtp.timeout | The socket I/O timeout value in milliseconds. | infinite timeout | Any Integer |
mail.smtp.from | The 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.localport | The 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.ehlo | If this parameter is set to false , you must not attempt to sign in with the EHLO command. | true | true or false |
mail.smtp.auth.login.disable | If this is set to true , it is not allowed to use the AUTH LOGIN command. | false | true or false |
mail.smtp.auth.plain.disable | If this parameter is set to true , it is not allowed to use the AUTH PLAIN command. | false | true or false |
mail.smtp.auth.digest-md5.disable | If this parameter is set to true , it is not allowed to use the AUTH DIGEST-MD5 command. | false | true or false |
mail.smtp.auth.ntlm.disable | If this parameter is set to true , it is not allowed to use the AUTH NTLM command | false | true or false |
mail.smtp.auth.ntlm.domain | The NTLM authentication domain. | None | The valid NTLM authentication domain name. |
mail.smtp.auth.ntlm.flags | NTLM protocol-specific flags. For more details, see http://curl.haxx.se/rfc/ntlm.html\#theNtlmFlags. | None | Valid NTLM protocol-specific flags. |
mail.smtp.dsn.notify | The NOTIFY option to the RCPT command. | None | Either NEVER , or a combination of SUCCESS , FAILURE , and DELAY (separated by commas). |
mail.smtp.dsn.ret | The RET option to the MAIL command. | None | Either FULL or HDRS . |
mail.smtp.sendpartial | If 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. | false | true or false |
mail.smtp.sasl.enable | If this parameter is set to true , the system attempts to use the javax.security.sasl package to choose an authentication mechanism for the login. | false | true or false |
mail.smtp.sasl.mechanisms | Enter a space or a comma-separated list of SASL mechanism names that the system shouldt try to use. | None | |
mail.smtp.sasl.authorizationid | The authorization ID to be used in the SASL authentication. If no value is specified, the authentication ID (i.e., username) is used. | username | Valid ID |
mail.smtp.sasl.realm | The realm to be used with the DIGEST-MD5 authentication. | None | |
mail.smtp.quitwait | If 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. | false | true or false |
mail.smtp.reportsuccess | If this parameter is set to true , the transport to includes an SMTPAddressSucceededException for each address to which the message is successfully delivered. | false | true or false |
mail.smtp.socketFactory | If this parameter is set to a class that implements the javax.net.SocketFactory interface, this class is used to create SMTP sockets. | None | Socket Factory |
mail.smtp.socketFactory.class | If 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.fallback | If 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. | true | true or false |
mail.smtp.socketFactory.port | This specifies the port to connect to when using the specified socket factory. | 25 | Valid port number |
mail.smtp.ssl.protocols | This specifies the SSL protocols that need to be enabled for the SSL connections. | None | This parameter specifies a whitespace separated list of tokens that are acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method. |
mail.smtp.starttls.enable | If 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. | false | true or false |
mail.smtp.starttls.required | If 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. | false | true or false |
mail.smtp.socks.host | This specifies the host name of a SOCKS5 proxy server to be used for the connections to the mail server. | None | |
mail.smtp.socks.port | This 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. | 1080 | valid port number |
mail.smtp.auth.ntlm.disable | If this parameter is set to true , the AUTH NTLM command cannot be issued. | false | true or false |
mail.smtp.mailextension | The extension string to be appended to the MAIL command. | None | |
mail.smtp.userset | If 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. | false | true 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.