Astroport.ONE/tools/mailjet.sh

131 lines
4.0 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
2023-12-31 12:35:34 +01:00
pseudo=$(echo $mail | cut -d '@' -f 1)
2023-12-31 13:39:42 +01:00
messfile="$2" # FICHIER A AJOUTER AU CORPS MESSAGEUP
2022-11-03 23:44:56 +01:00
SUBJECT="[UPlanet] $pseudo : $(myHostName)"
2023-12-31 13:39:42 +01:00
MESSAGEUP="MESSAGE
===
"
2023-12-18 15:32:45 +01:00
2023-12-31 13:39:42 +01:00
MESSAGESIGN="---
Astroport $(myHostName)
$(myIpfsGw)/ipns/$IPFSNODEID
2023-12-18 15:32:45 +01:00
"
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-18 15:32:45 +01:00
### SMTP RELAY
2023-12-17 17:32:13 +01:00
#~ echo "From: support@g1sms.fr
#~ To: EMAIL
#~ Bcc: support@qo-op.com
#~ Subject: SUBJECT
2023-12-31 13:39:42 +01:00
#~ $MESSAGEUP
2023-12-17 17:32:13 +01:00
#~ " > ~/.zen/tmp/email.txt
2023-12-18 15:32:45 +01:00
2023-12-17 17:32:13 +01:00
#~ [[ -s $messfile ]] && cat $messfile >> ~/.zen/tmp/email.txt \
#~ || echo "$messfile" >> ~/.zen/tmp/email.txt
2023-12-18 15:32:45 +01:00
#~ cat ~/.zen/tmp/email.txt | sed "s~EMAIL~${mail}~g" | sed "s~SUBJECT~${SUBJECT}~g" | /usr/sbin/ssmtp ${mail}
2023-12-17 17:32:13 +01:00
############# 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-31 13:39:42 +01:00
# MESSAGEUP HEADER
echo "$MESSAGEUP" > ~/.zen/tmp/email.txt
2023-12-31 12:35:34 +01:00
# + HTML in FILE
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-31 13:39:42 +01:00
echo $MESSAGESIGN >> ~/.zen/tmp/email.txt
2023-12-18 15:32:45 +01:00
EMAILZ=$(ipfs add -q ~/.zen/tmp/email.txt)
echo "/ipfs/${EMAILZ}"
TEXTPART=$(cat ~/.zen/tmp/email.txt | sed ':a;N;$!ba;s/\n/\\n/g' | tr '"' '\\\"')
HTMLPART=$(cat ~/.zen/tmp/email.txt | sed ':a;N;$!ba;s/\n/<br>/g' | tr '"' '\\\"')
2023-12-31 13:39:42 +01:00
export TEXTPART="$(myIpfsGw)/ipfs/${EMAILZ}"
2023-12-18 15:32:45 +01:00
json_payload='{
"Messages": [
{
"From": {
"Email": "'${SENDER_EMAIL}'",
"Name": "UPlanet"
},
"To": [
{
"Email": "'${RECIPIENT_EMAIL}'",
2023-12-31 19:22:16 +01:00
"Name": "'${pseudo}' Astronaut"
2023-12-18 15:32:45 +01:00
}
],
2023-12-26 17:53:33 +01:00
"Bcc": [
{
"Email": "support@g1sms.fr",
"Name": "SUPPORT"
}
],
2023-12-18 15:32:45 +01:00
"Subject": "'${SUBJECT}'",
2023-12-30 20:16:39 +01:00
"TextPart": "'$(myIpfsGw)/ipfs/${EMAILZ}'",
2023-12-31 12:35:34 +01:00
"HTMLPart": "<h3>You have a <br><a href=\"'$(myIpfsGw)'/ipfs/'${EMAILZ}'\">MESSAGE</a>!</h3><br />May the good vibes be with you!<br>Astroport UPlanet"
2023-12-18 15:32:45 +01:00
}
]
}'
# Verify the JSON structure with jq
echo "$json_payload" | jq .
2023-12-17 17:32:13 +01:00
# Run:
2023-12-18 15:32:45 +01:00
# POSSIBLE ! "HTMLPart": "<h3>You have a message <br><a href=\"https://qo-op.com/\">UPlanet</a>!</h3><br />May the good vibes be with you!"
2023-12-17 17:32:13 +01:00
curl -s \
-X POST \
2023-12-18 15:32:45 +01:00
--user "${MJ_APIKEY_PUBLIC}:${MJ_APIKEY_PRIVATE}" \
2023-12-17 17:32:13 +01:00
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
2023-12-18 15:32:45 +01:00
-d "$json_payload"
2022-11-03 02:45:35 +01:00
2023-12-18 15:32:45 +01:00
# This call sends an email to one recipient.
#~ curl -s \
#~ -X POST \
#~ --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
#~ https://api.mailjet.com/v3/send \
#~ -H 'Content-Type: application/json' \
#~ -d '{
#~ "FromEmail":"'${SENDER_EMAIL}'",
#~ "FromName":"UPlanet Support Team",
#~ "Subject":"Message from Astroport",
#~ "Text-part":"'${TEXTPART}'",
#~ "Html-part":"'${HTMLPART}'",
#~ "Recipients":[{"Email":"'${RECIPIENT_EMAIL}'"}]
#~ }'