Skip to content

Instantly share code, notes, and snippets.

@jeeyoungk
Created April 13, 2012 22:07
Show Gist options
  • Save jeeyoungk/2380454 to your computer and use it in GitHub Desktop.
Save jeeyoungk/2380454 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# pam_notify.py
# Author : Jeeyoung Kim
# Python script to notify user on login
FROM_ADDRESS = 'admin@example.com'
TO_ADDRESS = 'you@example.com'
def pam_sm_open_session(pamh, flags, args):
try:
from email.mime.text import MIMEText
import smtplib
import socket
user = pamh.get_user()
msg = MIMEText('')
msg['Subject'] = 'User [%s] logged into [%s].' % (user, socket.getfqdn())
msg['From'] = FROM_ADDRESS
msg['To'] = TO_ADDRESS
s = smtplib.SMTP('localhost')
s.sendmail(FROM_ADDRESS, [TO_ADDRESS], msg.as_string())
s.quit()
except Exception, e: pass
return pamh.PAM_SUCCESS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment