3.7 KiB
3.7 KiB
title, template, taxonomy, api
| title | template | taxonomy | api | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Send Email | api-endpoint |
|
|
Usage Notes
Required Headers
X-API-Key: grav_your_api_key
X-Grav-Environment: localhost
Content-Type: application/json
Multiple Recipients
Send to multiple recipients by comma-separating addresses:
{
"to": "user1@example.com, user2@example.com",
"subject": "Team Update",
"body": "<p>Hello team!</p>"
}
Or use named addresses:
{
"to": "Alice <alice@example.com>, Bob <bob@example.com>"
}
Plain Text Emails
Set content_type to send plain text instead of HTML:
{
"to": "user@example.com",
"subject": "Plain text message",
"body": "This is a plain text email.\n\nNo HTML formatting.",
"content_type": "text/plain"
}
Example with cURL
curl -X POST "https://yoursite.com/api/v1/email/send" \
-H "X-API-Key: grav_your_key" \
-H "X-Grav-Environment: localhost" \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Hello from Grav",
"body": "<h1>Hello</h1><p>Sent via the API</p>"
}'
Error Handling
If the email transport fails (e.g., SMTP connection error), the API returns a 500 error with details:
{
"status": 500,
"title": "Internal Server Error",
"detail": "Failed to send email: Connection to smtp.example.com:587 timed out"
}