Email module

Email module

This module can be used to send a message to a specific email address, either by a certain condition or at the end of a simulation Our example below shows how it can be executed at the end of a simulation.

This module can be used in combination with *FUNCTION but it's best used post-simulation with atexit.

Module Contents
mail = Mail( smtp-server , port = 25 , username = "" , password = "" )
Creates and returns a mail object. The first parameter is mandatory while the last three are optional. username and password are used for TLS authentication.
mail.send( recipient , sender )
Execute this function to send an email to the recipient. To minimize the risk of the email from being marked as spam, a sender address is required.
mail.attach_info( )
This function will attach to the email. The file will be converted to html format in order to preserve the monospace structure.
mail.attach_timing_info( )
Same as function above but with only the timing info.
mail.attach_file( file )
Attach a custom file (i.e. .out files) to the email.
mail.set_subject( subject )
Normally, the default subject is set to "Simulation finished" but this can be changed by calling this function.
mail.set_message( msg )
Appends text to message body.

The function sendMail() will be executed when the simulation end because of the use of atexit.register(). The example also shows the use of inclusion of as attachment.

Python script:
# Import atexit module
import atexit

# Import the email module
from mail import Mail

# Function to be executed when the simulation ends
def sendMail():
    # Create the mail object
    mail = Mail("smtp-server", 587)
    mail.send("", "")

# Call the above function when the simulation finishes
# Adding the python file to our input file *SCRIPT_PYTHON