Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send an Email notification when a specific show is added to Plex
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 = '' # From email address
to = '' # To email address
email_server = '' # Email server (Gmail:
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.login(email_username, email_password)
mailserver.sendmail(from, to, message.as_string())

This comment has been minimized.

Copy link

mp998 commented Apr 14, 2016

I played with the code a little and found a workaround for embedding the poster in the email. I also changed it so instead of matches it by the shows name it will send if it is the correct type (movie/episode).

Here is what it looks like:

Here is the link to the script


This comment has been minimized.

Copy link

goku-son commented Aug 7, 2016

Hello @mp998,

I am trying to use this script you created but whenever a item is added and the script executed, I get the following error in the log and no email is sent:

PlexPy Notifiers :: Script returned: Traceback (most recent call last):
File "C:\Program Files (x86)\PlexPY\Scripts\", line 8, in
    show_name = sys.argv[1]

IndexError: list index out of range

Any ideas on why I may be getting this error? I am not a python guy but some research on the error seems to suggest that a parameter needs to be passed to the script but I thought plexpy would do that. Any suggestions would be greatly appreciated. Thanks in advance.


This comment has been minimized.

Copy link

sibberio commented Jan 9, 2017

Hi all,
Any idea why I cannot get season and episode number? Here the body of my email

NCIS: New Orleans S00 - E01 -- -- aggiunto a Spettacoli TV su PLEX

As you can see for every shows I got S00 and E01. Thanks for your help


This comment has been minimized.

Copy link

rmanus commented Sep 29, 2017

@sibberio ,

I'm using PlexPy for Notifications and I had the same problem.
I resolved it by unchecking "Group notifications for recently added TV Shows or Music" under Notifications settings


This comment has been minimized.

Copy link

wcapes21 commented Oct 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.