I made a script that will send an email or SMS notification with a custom message. It’s only for Linux but Windows 10 users might be able to use the Linux command line feature to use it but I have not tested it. It uses curl to send email since my Sonarr runs in a docker that does not have extra tools like PHP. Just change the variables as needed. Here is the script:
#!/bin/bash template="/config/scripts/template.txt" receiver="email@example.com" sender="firstname.lastname@example.org" smtp="smtps://smtp.gmail.com:465" apikey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx sonarr_address="http://localhost:8989" netrc="/config/scripts/.netrc" sonarr_episode_title=$(curl -s $sonarr_address/api/episode?seriesId=$sonarr_series_id --header "X-Api-Key:$apikey" | jq -r ". | select(.episodeFileId==$sonarr_episodefile_id) | .title") sonarr_episode_description=$(curl -s $sonarr_address/api/episode?seriesId=$sonarr_series_id --header "X-Api-Key:$apikey" | jq -r ". | select(.episodeFileId==$sonarr_episodefile_id) | .overview") eval "cat <<EOF $(<$template) EOF " 2> /dev/null | curl -s --netrc-file $netrc --ssl-reqd --mail-from $sender --mail-rcpt $receiver --url $smtp -T -
And here is a sample template:
From: "Media Server" <email@example.com> To: "Me" <firstname.lastname@example.org> Subject: Hey, there's a new episode of "$sonarr_series_title" available to watch: Season $sonarr_episodefile_seasonnumber episode $sonarr_episodefile_episodenumbers $sonarr_episode_title $sonarr_episode_description
A couple of notes:
Username and password for the email account is stored in .netrc file.
Multiepisode files will give “null” for the description because I did not bother accounting for that circumstance. I don’t have the time nor desire at the moment.
To send SMS, you need to use your carrier’s email to SMS feature. Read here:
I would recommend using the MMS gateway as SMS gateways have more restrictions such as character limit. This usually means you cannot send episode description. For an example, sending an email to email@example.com will send a message to that phone number. Also, send a blank subject if using SMS.
The two variables “sonarr_episode_title” and “sonarr_episode_description” require you download jq (https://stedolan.github.io/jq/), as it will parse the value from the Sonarr API for those. If you don’t want to use those variables in your notification, just comment those lines out and don’t bother downloading jq. You also won’t need to change the API variable or Sonarr address variable I know I am querying the API twice, once for each variable, instead of just once and then parsing it and assigning it to two variables but I couldn’t get it to work and I don’t yet have the time to fix it. Feel free to school me if you get it figured out.
The “to” and “from” isn’t strictly needed in the template as those are in the Curl command. They are especially not needed for SMS but for an email it will let you personalize the name of the sender and receiver.
You can have multiple templates and multiple copies of the script with different settings for different users. That way you can have custom notifications for multiple users. Let me know if anyone has any questions or issues.