Send emails programmatically using Mailgun's HTTP API.
Configure the following environment variables in ~/.zshrc or ~/.bash_profile:
export MAILGUN_API_KEY="key-xxxxx" # Your Mailgun private API key
export MAILGUN_DOMAIN="mg.yourdomain.com" # Your Mailgun domain
export MAILGUN_FROM="Sender <noreply@mg.yourdomain.com>" # Default sender
export MAILGUN_DEFAULT_TO="you@email.com" # Default recipient (optional)
Then reload your shell configuration:
source ~/.zshrc
mailgun/scripts/send_email.sh "Subject" "Email body text"
mailgun/scripts/send_email.sh "Newsletter" "Content here" "recipient@email.com"
mailgun/scripts/send_email.sh "Alert" "System down" "admin@company.com" "alerts@company.com"
Error: MAILGUN_API_KEY and MAILGUN_DOMAIN must be set
→ Configure environment variables as shown in Prerequisites
Error: 401 Unauthorized
→ Check that your API key is correct and active
Error: 404 Not Found
→ Verify your MAILGUN_DOMAIN is correct
共 2 个版本