Custom Python in Omniscope to send emails

Posted over 5 years ago by Deborah

Post a topic
Un Answered

Hello there, just posting a Python script that I wrote and embedded in Omniscope to send email when I find a certain value in my dataset (i.e. a failure condition)



import pandas as pd
import smtplib

mail_user = ''  
mail_password = 'yourpassword'

sent_from = mail_user  
to = ['', ']  
subject = 'Important Message'  
body = ''

#Check a special condition
for index, row in input_data.iterrows(): 
  if (row[0] == "FAILURE"): 
    #Construct the message to send
    body = 'Failure found - ' + row[1] 
    #Do not touch these lines below until the break keyword!
    email_text = """\
From: %s
To: %s
Subject: %s

""" % (sent_from, ", ".join(to), subject, body)

#If the condition was met,  send the email
if body:
	#Email Server config, and connect
	server = smtplib.SMTP_SSL('', 465)
	#Next, log in to the server
	server.login(mail_user, mail_password)
    #Send the mail
	server.sendmail(sent_from, to, email_text)
    #Quit the connection
	#Output the message sent to Python block output
	output_data = pd.DataFrame(["Sent "+ body], columns=["Result"])
	#do nothing, output no message was sent
	output_data = pd.DataFrame(["Nothing to send"], columns=["Result"])



1 Votes


Antonio Poggi

Antonio Poggi posted over 5 years ago Admin

Thank you Deborah, 

For more complex email you can use the Python modules email.MIMEMultipart and email.MIMEText,  found in the basic Python libraries.

N.B. we will be adding the email block in Omniscope 2019 (in Q1). In the meantime your script is a super valid and useful alternative!

2 Votes

Login or Sign up to post a comment