Last active
September 11, 2025 23:48
-
-
Save szepeviktor/0a7993ba4b96c0098510937913277769 to your computer and use it in GitHub Desktop.
Twilio SMS to email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Send SMS with Twilio API. | |
| # | |
| export LC_ALL="C.UTF-8" | |
| declare -a iso1_to_gsm=( | |
| 'À' 'Ä' 'Â' 'Ä' 'Ã' 'Ä' | |
| 'È' 'É' 'Ê' 'É' 'Ë' 'É' | |
| 'Ì' 'I' 'Î' 'I' 'Ï' 'I' | |
| 'Ð' 'D' | |
| 'Ò' 'Ö' 'Ô' 'Ö' 'Õ' 'Ö' | |
| 'Ù' 'Ü' 'Û' 'Ü' | |
| 'Ý' 'Y' 'Þ' 'T' | |
| 'â' 'à' 'ã' 'à' | |
| 'ê' 'é' 'ë' 'è' | |
| 'î' 'ì' 'ï' 'ì' | |
| 'ð' 'd' | |
| 'ô' 'ò' 'õ' 'ò' | |
| 'û' 'ù' | |
| 'ý' 'y' 'þ' 't' 'ÿ' 'y' | |
| '¢' 'c' '¦' 'I' '©' 'C' '®' 'R' 'ª' 'a' | |
| '«' '<' '¬' '-' '¯' '-' | |
| '°' 'o' '±' '+' '²' '2' '³' '3' '´' "'" | |
| 'µ' 'u' '¶' 'P' '·' '.' | |
| '¸' ',' '¹' '1' 'º' 'o' '»' '>' '¼' '/' | |
| '½' '/' '¾' '/' '×' 'x' '÷' '/' '¨' '"' | |
| ) | |
| TWILIO_FROM="YOUR-PHONE-NUMBER" | |
| TWILIO_TO="$1" | |
| TWILIO_API_KEY="YOUR-API-KEY" | |
| TWILIO_API_SECRET="$2" | |
| TWILIO_BODY=$( | |
| TTMP=$(mktemp -d) | |
| ripmime -q --name-by-type -i - -d "${TTMP}" | |
| printf -v sed_expr -- 's#%s#%s#g; ' "${iso1_to_gsm[@]}" | |
| cat "$(ls "${TTMP}"/text-plain* 2>/dev/null | head -n 1)" \ | |
| | sed -e 's#ő#ö#g; s#ű#ü#g; s#Ő#Ö#g; s#Ű#Ü#g' \ | |
| | iconv -f UTF-8 -t ISO_8859-1//TRANSLIT//IGNORE | iconv -f ISO_8859-1 -t UTF-8 \ | |
| | sed -e "${sed_expr}" \ | |
| | sed -e ':a;N;$!ba;s#\n\+#\n#g' \ | |
| | head -c 158 | |
| rm -rf "$TTMP" | |
| ) | |
| curl -sS "https://api.twilio.com/2010-04-01/Accounts/${TWILIO_API_KEY}/Messages.json" \ | |
| -X POST \ | |
| --data-urlencode "From=+${TWILIO_FROM}" \ | |
| --data-urlencode "To=+${TWILIO_TO}" \ | |
| --data-urlencode "Body=${TWILIO_BODY}" \ | |
| -u "${TWILIO_API_KEY}:${TWILIO_API_SECRET}" 2>&1 | logger --tag twilio-sms |
Author
Author
List ISO 8859-1 characters
for C in {A..F}{{0..9},{A..F}}; do printf "\\x${C}"; done|iconv -f latin1 -t utf8|fold -w 16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pipe email to this script: