From fe9b2a401072accc2942ee7b8894e730e2a31bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingvar=20S=C3=B8rlien?= <27728547+ingvarso@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:54:18 +0100 Subject: [PATCH] Create gmail-example.sh Adds an example of how gmail can be used to send reauthentication link. --- reader/nordigen/hooks/gmail-example.sh | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 reader/nordigen/hooks/gmail-example.sh diff --git a/reader/nordigen/hooks/gmail-example.sh b/reader/nordigen/hooks/gmail-example.sh new file mode 100644 index 0000000..ce2f273 --- /dev/null +++ b/reader/nordigen/hooks/gmail-example.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# This script will send and e-mail with reauthentication link using gmail +# +# Configuration is done in the /data/gmail_config.env +# Environment variables expected +# +# sender_email +# app_specific_password +# recipient +# + +# Check if the required parameters are provided +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Load Gmail credentials from the file +if [ -f "/data/gmail_config.env" ]; then + . "/data/gmail_config.env" +else + echo "Error: gmail_config.env file not found." + exit 1 +fi + +# Set the parameters +status="$1" +link="$2" + +# Check if msmtp is installed, and install it if not +if ! command -v msmtp > /dev/null; then + echo "Installing msmtp..." + apk update + apk add msmtp +fi + +# Create a temporary file for the email message +email_file=$(mktemp) +echo -e "Subject: YNABber needs reauthentication\n\nStatus: $status\nLink: $link" > "$email_file" + +# Generate the .msmtprc content +msmtprc_content=$(cat < ~/.msmtprc + +# Use msmtp to send the email +msmtp -a gmail -t "$recipient" < "$email_file" + +# Clean up the temporary file +rm "$email_file"