Astroport.ONE/tools/mailjet.sh

83 lines
2.9 KiB
Bash
Raw Normal View History

2022-10-28 13:14:02 +02:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2022.10.28
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
2023-12-17 17:32:13 +01:00
2022-10-28 13:14:02 +02:00
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
2022-12-29 14:51:05 +01:00
. "$MY_PATH/my.sh"
2022-10-28 13:14:02 +02:00
ME="${0##*/}"
2022-10-28 13:14:02 +02:00
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################'
### PLEASE CHANGE YOUR DOMAIN AND KEY ( OR HELP PAYING TRAFIC ;)
## THIS IS A FREE LIMITED ACCOUNT. DO NOT EXAGERATE ;)
2022-11-03 23:44:56 +01:00
mail="$1" # EMAIL DESTINATAIRE
2023-11-13 10:47:09 +01:00
[[ ! $1 ]] && mail="support@qo-op.com"
2022-12-08 20:31:04 +01:00
2022-11-16 17:31:46 +01:00
messfile="$2" # FICHIER A AJOUTER AU CORPS MESSAGE
2022-11-03 23:44:56 +01:00
2023-01-03 16:40:07 +01:00
SUBJECT="[(♥‿‿♥)] Station Astroport : $(myHostName)"
2022-12-08 23:19:09 +01:00
MESSAGE="( ◕‿◕)\n\n Bonjour $PLAYER\n\n UN MESSAGE POUR VOUS.\n\nAstroport\n/ipns/$IPFSNODEID"
2022-12-08 21:13:15 +01:00
echo "
2022-12-08 20:31:04 +01:00
########################################################################
2022-12-12 22:17:55 +01:00
# $SUBJECT + $messfile -> $mail
2022-12-08 21:13:15 +01:00
########################################################################"
2022-11-03 02:45:35 +01:00
2023-12-17 17:32:13 +01:00
#~ echo "From: support@g1sms.fr
#~ To: EMAIL
#~ Bcc: support@qo-op.com
#~ Subject: SUBJECT
#~ MESSAGE
#~ " > ~/.zen/tmp/email.txt
#~ [[ -s $messfile ]] && cat $messfile >> ~/.zen/tmp/email.txt \
#~ || echo "$messfile" >> ~/.zen/tmp/email.txt
#~ cat ~/.zen/tmp/email.txt | sed "s~EMAIL~${mail}~g" | sed "s~SUBJECT~${SUBJECT}~g" | sed "s~MESSAGE~${MESSAGE}~g" | /usr/sbin/ssmtp ${mail}
############# USING MAILJET API ###############
2022-11-03 23:44:56 +01:00
2023-12-17 17:32:13 +01:00
export MJ_APIKEY_PUBLIC='02b075c3f28b9797d406f0ca015ca984'
export MJ_APIKEY_PRIVATE='58256ba8ea62f68965879f53bbb29f90'
export SENDER_EMAIL='support@g1sms.fr'
export RECIPIENT_EMAIL=${mail}
2023-01-03 16:40:07 +01:00
2023-12-17 17:32:13 +01:00
echo "$MESSAGE" > ~/.zen/tmp/email.txt
2023-01-03 16:40:07 +01:00
[[ -s $messfile ]] && cat $messfile >> ~/.zen/tmp/email.txt \
|| echo "$messfile" >> ~/.zen/tmp/email.txt
2022-11-03 23:48:36 +01:00
2023-12-17 17:32:13 +01:00
# Run:
# POSSIBLE ! "HTMLPart": "<h3>Dear member, you have a message for you on <a href=\"https://qo-op.com/\">UPlanet</a>!</h3><br />May the good vibes be with you!"
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"Messages":[
{
"From": {
"Email": "'$SENDER_EMAIL'",
"Name": "UPlanet support"
},
"To": [
{
"Email": "'$RECIPIENT_EMAIL'",
"Name": "Astronaut TW"
}
],
"Subject": "'$SUBJECT'",
"TextPart": "'$(cat ~/.zen/tmp/email.txt)'"
}
]
}'
2022-11-03 02:45:35 +01:00