Skip to content

Instantly share code, notes, and snippets.

@erickbrower
Last active December 14, 2015 06:49
Show Gist options
  • Save erickbrower/5045325 to your computer and use it in GitHub Desktop.
Save erickbrower/5045325 to your computer and use it in GitHub Desktop.
eventcmd script for mcabber that sends an email when a new message arrives. Designed for use with Prowl.
#!/usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os, sys
gmail_user = "youremail@gmail.com"
gmail_pwd = "your password"
def mail(to, subject, text, attach = None):
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
if attach:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
mailServer.close()
if 'MSG' in sys.argv and 'IN' in sys.argv:
mail("your-prowl-api-key@api.prowlapp.com",
"New IM from: %s" % sys.argv[3], "Check it!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment