Last active
December 14, 2015 06:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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