Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Script:
#!/bin/bash
# Verifica se o SendGrid API Key foi fornecido
if [ -z "$1" ]; then
echo "Uso: $0 <SENDGRID_API_KEY> <para_email> <assunto> <mensagem>"
exit 1
fi
SENDGRID_API_KEY=$1
TO_EMAIL=$2
SUBJECT=$3
MESSAGE=$4
# Verifica se todos os parâmetros foram fornecidos
if [ -z "$TO_EMAIL" ] || [ -z "$SUBJECT" ] || [ -z "$MESSAGE" ]; then
echo "Uso: $0 <SENDGRID_API_KEY> <para_email> <assunto> <mensagem>"
exit 1
fi
# Cria o JSON para a requisição
JSON_PAYLOAD=$(cat <<EOF
{
"personalizations": [
{
"to": [
{
"email": "$TO_EMAIL"
}
],
"subject": "$SUBJECT"
}
],
"from": {
"email": "seu-email@exemplo.com"
},
"content": [
{
"type": "text/plain",
"value": "$MESSAGE"
}
]
}
EOF
)
# Envia a requisição para a API do SendGrid
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data "$JSON_PAYLOAD"
echo "Mensagem enviada para $TO_EMAIL com sucesso!"
Como Executar o Script:
enviar_email.sh
.chmod +x enviar_email.sh
../enviar_email.sh <SENDGRID_API_KEY> <para_email> <assunto> <mensagem>
Substitua <SENDGRID_API_KEY>
, <para_email>
, <assunto>
e <mensagem>
pelos valores apropriados.