Last active
October 2, 2017 09:52
-
-
Save JonnyWong16/2fbd4aeff11bc2452db3 to your computer and use it in GitHub Desktop.
Send an Email notification when a specific show is added to Plex
This file contains hidden or 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
from email.mime.text import MIMEText | |
import email.utils | |
import smtplib | |
import sys | |
# Arguments passed from PlexPy | |
# {show_name} {episode_name} {season_num} {episode_num} | |
show_name = sys.argv[1] | |
# You can add more arguments if you want more details in the email body | |
# episode_name = sys.argv[2] | |
# season_num = sys.argv[3] | |
# episode_num = sys.argv[4] | |
show_notify = 'Game of Thrones' # The show name you want notifications to send | |
# Email settings | |
name = 'Your name' # Your name | |
from = '[email protected]' # From email address | |
to = '[email protected]' # To email address | |
email_server = 'smtp.gmail.com' # Email server (Gmail: smtp.gmail.com) | |
email_port = 587 # Email port (Gmail: 587) | |
email_username = 'username' # Your email username | |
email_password = 'password' # Your email password | |
email_subject = 'Recently added to Plex' # The email subject | |
email_body = 'New episode for ' + show_name + ' is available!' # The email body | |
# email_body = 'New episode for ' + show_name + ' (S' + season_num + 'E' + episode_num + ') is available!' # More detailed email body | |
### Do not edit below ### | |
# Check if the show name is the one we want | |
if show_name.lower() == show_notify.lower(): | |
message = MIMEText(email_body, 'plain', "utf-8") | |
message['Subject'] = email_subject | |
message['From'] = email.utils.formataddr((name, from)) | |
message['To'] = to | |
mailserver = smtplib.SMTP(email_server, email_port) | |
mailserver.starttls() | |
mailserver.ehlo() | |
mailserver.login(email_username, email_password) | |
mailserver.sendmail(from, to, message.as_string()) | |
mailserver.quit() | |
else: | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - How can I make this work for multiple shows - eg: My wife watches Greys Anatomy and Empire and I want her to get emails for any new episodes of those 2 shows.
Thanks