# Automatically receive an email when an OpenFOAM simulation is complete

August 24, 2013 | 1 Minute Read

OpenFOAM runs can take a long time. Wouldn’t it be nice to know when a simulation is done without having to keep checking the terminal? As it turns out, this is very easy to set up with Python (I got most of the code I used from here, which details how to send an SMS). Simply create a script called send_email.py in the OpenFOAM case directory that looks like this:

#!/usr/bin/python

import smtplib
from email.mime.text import MIMEText

server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()

msg = MIMEText("The simulation is complete.")
msg["Subject"] = "Simulation finished"
msg["From"] = "Me"
msg["To"] = "Me"


Change the permissions such that the file can be executed as a program, then at the bottom of your Allrun script add
python send_email.py