Skip to content

Instantly share code, notes, and snippets.

@dawranliou
Created September 16, 2016 23:40
Show Gist options
  • Save dawranliou/6b79cb6519840b8b2ec0f6f77e632292 to your computer and use it in GitHub Desktop.
Save dawranliou/6b79cb6519840b8b2ec0f6f77e632292 to your computer and use it in GitHub Desktop.
Office pranks
import smtplib
import email.utils
from email.mime.text import MIMEText
from collections import namedtuple
Prankee = namedtuple('Prankee', 'name id email')
colleague = Prankee('Colleague', 'colleague_id', 'colleague@email.com')
subject = '[IT Information] %s we detect unauthorized actions from your account' % colleague.name
body = '''Dear user %s (%s),
IT detected unauthorized actions from your account.
If this wasn't you. It's very likely your account has been hacked.
Please change you credential immediately.
Have a great day,
-your friend in IT
''' % (colleague.id, colleague.name)
sender = ('IT-Information', 'IT.Information@email.com')
recipients = [(colleague.name, colleague.email)]
msg = MIMEText(body)
msg['To'] = ', '.join([email.utils.formataddr(recpt) for recpt in recipients])
msg['From'] = email.utils.formataddr(sender)
msg['Subject'] = subject
with smtplib.SMTP('mail') as server:
# server.set_debuglevel(True)
server.sendmail(sender, recipients, msg.as_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment