Skip to content

Instantly share code, notes, and snippets.

@floweb
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save floweb/72178fe149c7c84a5074 to your computer and use it in GitHub Desktop.

Select an option

Save floweb/72178fe149c7c84a5074 to your computer and use it in GitHub Desktop.
Mail some news about our sickbeard_sxxexx.py script
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author : Florian Le Frioux
# Date : October 2014
# Version 1.0
# Mail some news about our sickbeard_sxxexx.py script
import email.utils
from email.mime.text import MIMEText
import smtplib
import sys
import envoy
mail_from = 'mail@gmail.com'
mail_to_list = ['mail@toto.fr', 'mail@tata.fr']
server_name = 'smtp.gmail.com'
r = envoy.run('/bin/bash /var/www/sickbeard/scripts/sickbeard_sxxexx.sh')
msg_body = 'Standard Ouput:\r\n%s' % r.std_out
if r.std_err:
msg_body = '%s\r\n\r\nStandard Error:\r\n%s' % (msg_body, r.std_err)
# Create the message
msg = MIMEText(msg_body, 'plain', 'utf-8')
msg['Content-Type'] = "text/plain; charset=utf-8"
msg['Content-Transfer-Encoding'] = "quoted-printable"
msg['From'] = email.utils.formataddr(('Script téléchargement séries',
mail_from))
msg['To'] = ', '.join(mail_to_list)
msg['Subject'] = 'Des news du script sickbeard_sxxexx.py'
server = smtplib.SMTP(server_name)
#server.set_debuglevel(True)
try:
# identify ourselves, prompting server for supported features
server.ehlo()
# If we can encrypt this session, do it
if server.has_extn('STARTTLS'):
server.starttls()
server.ehlo() # re-identify ourselves over TLS connection
server.login('mail@gmail.com', 'password')
# Sending the mail
server.sendmail(mail_from, mail_to_list, msg.as_string())
finally:
server.quit()
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment