E-Mail senden

Senden Sie einzelne transaktionale E-Mails ueber den /v3/smtp/email-Endpunkt.

Endpunkt

POST /v3/smtp/email

Anfrage-Body

Einfache E-Mail

{
"sender": {
"name": "Your App",
"email": "[email protected]"
},
"to": [
{
"email": "[email protected]",
"name": "John Doe"
}
],
"subject": "Welcome to our service!",
"htmlContent": "<html><body><h1>Welcome!</h1><p>Thank you for signing up.</p></body></html>"
}

Erweiterte E-Mail

{
"sender": {
"name": "Your App",
"email": "[email protected]"
},
"to": [
{
"email": "[email protected]",
"name": "John Doe"
}
],
"cc": [
{
"email": "[email protected]",
"name": "CC User"
}
],
"bcc": [
{
"email": "[email protected]"
}
],
"subject": "Order Confirmation #{{order_id}}",
"htmlContent": "<html><body><h1>Order Confirmed</h1><p>Your order {{order_id}} has been confirmed.</p></body></html>",
"textContent": "Your order {{order_id}} has been confirmed.",
"params": {
"order_id": "12345"
},
"tags": ["transactional", "order-confirmation"],
"headers": {
"X-Custom-Header": "custom-value"
}
}

Code-Beispiele

JavaScript/Node.js

const brevo = require('@brevo/api');
const apiInstance = new brevo.TransactionalEmailsApi();
apiInstance.setApiKey(brevo.TransactionalEmailsApiApiKeys.apiKey, process.env.BREVO_API_KEY);
const sendEmail = async () => {
const sendSmtpEmail = new brevo.SendSmtpEmail();
sendSmtpEmail.subject = "Welcome to our service!";
sendSmtpEmail.htmlContent = "<html><body><h1>Welcome!</h1></body></html>";
sendSmtpEmail.sender = { name: "Your App", email: "[email protected]" };
sendSmtpEmail.to = [{ email: "[email protected]", name: "John Doe" }];
try {
const result = await apiInstance.sendTransacEmail(sendSmtpEmail);
console.log('Email sent:', result);
return result;
} catch (error) {
console.error('Error sending email:', error);
throw error;
}
};

Python

import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_API_KEY'
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(
to=[{"email": "[email protected]", "name": "John Doe"}],
sender={"name": "Your App", "email": "[email protected]"},
subject="Welcome to our service!",
html_content="<html><body><h1>Welcome!</h1></body></html>"
)
try:
api_response = api_instance.send_transac_email(send_smtp_email)
print(api_response)
except ApiException as e:
print("Exception when calling TransactionalEmailsApi->send_transac_email: %s\n" % e)

cURL

Terminal window
curl -X POST "https://api.brevo.com/v3/smtp/email" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY" \
-d '{
"sender": {
"name": "Your App",
"email": "[email protected]"
},
"to": [
{
"email": "[email protected]",
"name": "John Doe"
}
],
"subject": "Welcome to our service!",
"htmlContent": "<html><body><h1>Welcome!</h1></body></html>"
}'

Antwort

Erfolgreiche Antwort (201 Created)

{
"messageId": "<[email protected]>"
}

Fehlerantworten

Ungueltiger API-Schluessel (401)

{
"code": "unauthorized",
"message": "Invalid API key provided"
}

Ungueltiges E-Mail-Format (400)

{
"code": "invalid_parameter",
"message": "Invalid email format in 'to' field"
}

Ratenlimit ueberschritten (429)

{
"code": "too_many_requests",
"message": "Rate limit exceeded"
}

Parameter

Erforderliche Parameter

ParameterTypBeschreibung
senderobjectAbsenderinformationen
toarrayArray von Empfaengerobjekten
subjectstringE-Mail-Betreffzeile

Optionale Parameter

ParameterTypBeschreibung
htmlContentstringHTML-Inhalt der E-Mail
textContentstringTextinhalt der E-Mail
ccarrayCC-Empfaenger
bccarrayBCC-Empfaenger
replyToobjectAntwortadresse
attachmentsarrayDateianhange
paramsobjectVorlagenparameter
tagsarrayE-Mail-Tags zur Nachverfolgung
headersobjectBenutzerdefinierte Header

Vorlagenvariablen

Verwenden Sie Vorlagenvariablen in Ihrem Betreff und Inhalt:

{
"subject": "Welcome {{firstName}}!",
"htmlContent": "<h1>Hello {{firstName}} {{lastName}}</h1>",
"params": {
"firstName": "John",
"lastName": "Doe"
}
}

Anhaenge

Dateianhange einfuegen:

{
"attachments": [
{
"content": "base64_encoded_content",
"name": "invoice.pdf"
},
{
"url": "https://example.com/document.pdf",
"name": "document.pdf"
}
]
}

Best Practices

  1. Immer sowohl HTML- als auch Textinhalt einschliessen fuer bessere Zustellbarkeit
  2. Vorlagenvariablen verwenden anstatt Inhalte zu verketten
  3. Korrekte Absenderinformationen angeben um Spamfilter zu vermeiden
  4. Tags hinzufuegen fuer Nachverfolgung und Analysen
  5. E-Mail-Adressen validieren vor dem Versand
  6. Fehler korrekt behandeln mit Wiederholungslogik

Ratenbegrenzungen

  • Kostenlose Konten: 300 E-Mails/Tag
  • Bezahlte Konten: Abhaengig von Ihrem Tarif
  • Burst-Limit: 100 E-Mails/Minute

Tracking

Ueber diesen Endpunkt gesendete E-Mails werden automatisch verfolgt fuer:

  • Zustellungsstatus
  • Oeffnungsraten
  • Klickverfolgung
  • Bounce-Verarbeitung

Detaillierte Analysen finden Sie in Ihrem Brevo Dashboard unter Statistiken -> Transaktional.

Verwandte Endpunkte

AI-Assistent

Hallo! Fragen Sie mich alles über die Dokumentation.

Kostenlos mit Brevo starten