Skip to content

Instantly share code, notes, and snippets.

@xlcommunity
Last active August 29, 2015 14:24
Show Gist options
  • Save xlcommunity/248c060d291f1945613e to your computer and use it in GitHub Desktop.
Save xlcommunity/248c060d291f1945613e to your computer and use it in GitHub Desktop.
Example custom notification task
#
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
#
import sys
from org.apache.commons.mail import EmailException, SimpleEmail
SOCKET_TIMEOUT = 30000 # 30s
email = SimpleEmail()
email.setHostName(smtpServer['host'])
email.setSmtpPort(smtpServer['port'])
if smtpServer['username']:
email.setAuthentication(smtpServer['username'], smtpServer['password'])
email.setSocketConnectionTimeout(SOCKET_TIMEOUT);
email.setSocketTimeout(SOCKET_TIMEOUT);
try:
email.setFrom(fromAddress)
for toAddress in toAddresses.split(','):
email.addTo(toAddress)
if ccAddresses:
for ccAddress in ccAddresses.split(','):
email.addCc(ccAddress)
if bccAddresses:
for bccAddress in bccAddresses.split(','):
email.addBcc(bccAddress)
if replyToAddress:
email.addReplyTo(replyToAddress)
email.setSubject(subject)
email.setMsg(body)
email.send()
except EmailException, e:
print 'ERROR: Unable to send notification due to:', e
sys.exit(1)
<!--
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
-->
<type type="my.SmtpServer" extends="xlrelease.Configuration">
<property name="host" />
<property name="port" kind="integer" />
<property name="username" required="false" />
<property name="password" password="true" required="false" />
</type>
<type type="my.CustomNotification" extends="xlrelease.PythonScript">
<property name="taskColor" hidden="true" default="D3D3D3"/>
<property name="iconLocation" hidden="true" default="my/custom-notification-icon.png"/>
<property name="smtpServer" kind="ci" referenced-type="my.SmtpServer" category="input" />
<property name="fromAddress" label="From" category="input" />
<property name="toAddresses" label="To" category="input" />
<property name="ccAddresses" label="CC" category="input" required="false" />
<property name="bccAddresses" label="BCC" category="input" required="false" />
<property name="replyToAddress" label="Reply-to" category="input" required="false" />
<property name="subject" category="input" required="false" />
<property name="body" size="large" category="input" required="false" />
</type>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment