Email through a Hook



I am working on designing a Hook that monitors PBS resources. I am looking forward to implement email functionality wherein my Hook could send email to the users if their resources requested or used criteria is not met.

I had tried multiple ways to implement email feature in Hook through SMTP process but its not working out. Is there any other way?


Please let us know in which hook event you tried this ? Also, if you can share the hook with the community ( if it can be shared ) .

  1. Please check whether you are able to send a mail via python script from the PBS Server host and PBS Compute nodes without using/calling it in a PBS hook.
  2. Then you can call that script in runjob hook or server periodic hook or exechost_periodic hook by passing the required values.

Thank you


Hi Adarsh,

Below is the Hook:

When it writes an email has been triggered to the system admin there I need to implement email logic

Answer to your queries:

  1. Yes I am able to send mail by using the below script through server
    Subject: Test Send Mail
    Hello World
    control d (this key combination of control key and d will finish the email.)

I had tried using Python as well bu the below is not working out
import smtplib
server = smtplib.SMTP(‘’, 587)

#Next, log in to the server
server.login(“youremailusername”, “password”)

#Send the mail
msg = "
Hello!" # The /n separates the message from the headers
server.sendmail("", "", msg)


Hi Rakhen,

The below exechost_epilogue works for me and i receive mail too.

import os,sys
import pbs
e = pbs.event()
    if e.job.in_ms_mom():
        walltime_used = str(e.job.resources_used["walltime"])
        cputime_used = str(e.job.resources_used["cput"])
        mem_used = str(e.job.resources_used["mem"])
        report_file = str("/tmp/abc.txt")
        pbs.logmsg(pbs.LOG_DEBUG, "report_usage file is %s" % report_file)

        fd_out = open(report_file, 'w+')
        print >> fd_out, 'Walltime used is = ' + walltime_used
        print >> fd_out, 'CPU Time used is = ' + cputime_used
        print >> fd_out, 'Memory used is   = ' + mem_used

        mail_cmd="/bin/mail -s \"PBS OSS\" < /tmp/abc.txt"
        pbs.logmsg(pbs.LOG_DEBUG, "mail_command  is %s" % mail_cmd)

except SystemExit:
    pbs.logmsg(pbs.LOG_DEBUG, "report_usage: failed with %s" % str(sys.exc_info()))

I hope this helps