post https://api.brevo.com/v3/smtp/email
📨
Bulk Send and Customise Transactional Messages in Node.js
Open Recipe
✉️
Send Transactional Emails in Node.js
Open Recipe
✉️
Send a Transactional Email in Python
Open Recipe
Code Examples
You can use as reference the code below to implement this call in your preferred language.
Check all our official API clients here
const brevo = require('@getbrevo/brevo');
let defaultClient = brevo.ApiClient.instance;
let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'xkeysib-YOUR_API_KEY';
let apiInstance = new brevo.TransactionalEmailsApi();
let sendSmtpEmail = new brevo.SendSmtpEmail();
sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.htmlContent = "<html><body><h1>Common: This is my first transactional email {{params.parameter}}</h1></body></html>";
sendSmtpEmail.sender = { "name": "John", "email": "[email protected]" };
sendSmtpEmail.to = [
{ "email": "[email protected]", "name": "sample-name" }
];
sendSmtpEmail.replyTo = { "email": "[email protected]", "name": "sample-name" };
sendSmtpEmail.headers = { "Some-Custom-Name": "unique-id-1234" };
sendSmtpEmail.params = { "parameter": "My param value", "subject": "common subject" };
apiInstance.sendTransacEmail(sendSmtpEmail).then(function (data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function (error) {
console.error(error);
});
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: api-key
$config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer');
// Configure API key authorization: partner-key
$config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKey('partner-key', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Brevo\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('partner-key', 'Bearer');
$apiInstance = new Brevo\Client\Api\TransactionalEmailsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$sendSmtpEmail = new \Brevo\Client\Model\SendSmtpEmail([
'subject' => 'from the PHP SDK!',
'sender' => ['name' => 'Brevo', 'email' => '[email protected]'],
'replyTo' => ['name' => 'Brevo', 'email' => '[email protected]'],
'to' => [[ 'name' => 'Max Mustermann', 'email' => '[email protected]']],
'htmlContent' => '<html><body><h1>This is a transactional email {{params.bodyMessage}}</h1></body></html>',
'params' => ['bodyMessage' => 'made just for you!']
]); // \Brevo\Client\Model\SendSmtpEmail | Values to send a transactional email
try {
$result = $apiInstance->sendTransacEmail($sendSmtpEmail);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionalEmailsApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}
?>
from __future__ import print_function
import time
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint
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))
subject = "My Subject"
html_content = "<html><body><h1>This is my first transactional email </h1></body></html>"
sender = {"name":"John Doe","email":"[email protected]"}
to = [{"email":"[email protected]","name":"Jane Doe"}]
cc = [{"email":"[email protected]","name":"Janice Doe"}]
bcc = [{"name":"John Doe","email":"[email protected]"}]
reply_to = {"email":"[email protected]","name":"John Doe"}
headers = {"Some-Custom-Name":"unique-id-1234"}
params = {"parameter":"My param value","subject":"New Subject"}
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(to=to, bcc=bcc, cc=cc, reply_to=reply_to, headers=headers, html_content=html_content, sender=sender, subject=subject)
try:
api_response = api_instance.send_transac_email(send_smtp_email)
pprint(api_response)
except ApiException as e:
print("Exception when calling SMTPApi->send_transac_email: %s\n" % e)
const SibApiV3Sdk = require('sib-api-v3-typescript');
let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail();
sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.htmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
sendSmtpEmail.sender = {"name":"John Doe","email":"[email protected]"};
sendSmtpEmail.to = [{"email":"[email protected]","name":"Jane Doe"}];
sendSmtpEmail.cc = [{"email":"[email protected]","name":"Janice Doe"}];
sendSmtpEmail.bcc = [{"name":"John Doe","email":"[email protected]"}];
sendSmtpEmail.replyTo = {"email":"[email protected]","name":"John Doe"};
sendSmtpEmail.headers = {"Some-Custom-Name":"unique-id-1234"};
sendSmtpEmail.params = {"parameter":"My param value","subject":"New Subject"};
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
console.error(error);
});
package sibApi;
import sendinblue.ApiClient;
import sendinblue.Configuration;
import sendinblue.auth.ApiKeyAuth;
import sibModel.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.List;
public class Program {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: api-key
ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("api-key");
apiKey.setApiKey("YOUR API KEY");
try {
AllRouteExamples obj = new AllRouteExamples();
TransactionalEmailsApi api = new TransactionalEmailsApi();
SendSmtpEmailSender sender = new SendSmtpEmailSender();
sender.setEmail("[email protected]");
sender.setName("John Doe");
List<SendSmtpEmailTo> toList = new ArrayList<SendSmtpEmailTo>();
SendSmtpEmailTo to = new SendSmtpEmailTo();
to.setEmail("[email protected]");
to.setName("John Doe");
toList.add(to);
List<SendSmtpEmailCc> ccList = new ArrayList<SendSmtpEmailCc>();
SendSmtpEmailCc cc = new SendSmtpEmailCc();
cc.setEmail("[email protected]");
cc.setName("Janice Doe");
ccList.add(cc);
List<SendSmtpEmailBcc> bccList = new ArrayList<SendSmtpEmailBcc>();
SendSmtpEmailBcc bcc = new SendSmtpEmailBcc();
bcc.setEmail("[email protected]");
bcc.setName("John Doe");
bccList.add(bcc);
SendSmtpEmailReplyTo replyTo = new SendSmtpEmailReplyTo();
replyTo.setEmail("[email protected]");
replyTo.setName("John Doe");
SendSmtpEmailAttachment attachment = new SendSmtpEmailAttachment();
attachment.setName("test.jpg");
byte[] encode = Files.readAllBytes(Paths.get("local_filepath\\test.jpg"));
attachment.setContent(encode);
List<SendSmtpEmailAttachment> attachmentList = new ArrayList<SendSmtpEmailAttachment>();
attachmentList.add(attachment);
Properties headers = new Properties();
headers.setProperty("Some-Custom-Name", "unique-id-1234");
Properties params = new Properties();
params.setProperty("parameter", "My param value");
params.setProperty("subject", "New Subject");
SendSmtpEmail sendSmtpEmail = new SendSmtpEmail();
sendSmtpEmail.setSender(sender);
sendSmtpEmail.setTo(toList);
sendSmtpEmail.setCc(ccList);
sendSmtpEmail.setBcc(bccList);
sendSmtpEmail.setHtmlContent("<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>");
sendSmtpEmail.setSubject("My {{params.subject}}");
sendSmtpEmail.setReplyTo(replyTo);
sendSmtpEmail.setAttachment(attachmentList);
sendSmtpEmail.setHeaders(headers);
sendSmtpEmail.setParams(params);
List<SendSmtpEmailTo1> toList1 = new ArrayList<SendSmtpEmailTo1>();
SendSmtpEmailTo1 to1 = new SendSmtpEmailTo1();
to1.setEmail("[email protected]");
to1.setName("John Doe");
toList1.add(to1);
List<SendSmtpEmailMessageVersions> messageVersions = new ArrayList<>();
SendSmtpEmailMessageVersions versions1 = new SendSmtpEmailMessageVersions();
SendSmtpEmailMessageVersions versions2 = new SendSmtpEmailMessageVersions();
versions1.to(toList1);
versions2.to(toList1);
messageVersions.add(versions1);
messageVersions.add(versions2);
sendSmtpEmail.setMessageVersions(messageVersions);
sendSmtpEmail.setTemplateId(1L);
CreateSmtpEmail response = api.sendTransacEmail(sendSmtpEmail);
System.out.println(response.toString());
} catch (Exception e) {
System.out.println("Exception occurred:- " + e.getMessage());
}
}
}
using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;
using System;
using System.Diagnostics;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace Sendinblue
{
class Program
{
static void Main(string[] args)
{
Configuration.Default.ApiKey.Add("api-key", "YOUR API KEY");
var apiInstance = new TransactionalEmailsApi();
string SenderName = "John Doe";
string SenderEmail = "[email protected]";
SendSmtpEmailSender Email = new SendSmtpEmailSender(SenderName, SenderEmail);
string ToEmail = "[email protected]";
string ToName = "John Doe";
SendSmtpEmailTo smtpEmailTo = new SendSmtpEmailTo(ToEmail, ToName);
List<SendSmtpEmailTo> To = new List<SendSmtpEmailTo>();
To.Add(smtpEmailTo);
string BccName = "Janice Doe";
string BccEmail = "[email protected]";
SendSmtpEmailBcc BccData = new SendSmtpEmailBcc(BccEmail, BccName);
List<SendSmtpEmailBcc> Bcc = new List<SendSmtpEmailBcc>();
Bcc.Add(BccData);
string CcName = "John Doe";
string CcEmail = "[email protected]";
SendSmtpEmailCc CcData = new SendSmtpEmailCc(CcEmail, CcName);
List<SendSmtpEmailCc> Cc = new List<SendSmtpEmailCc>();
Cc.Add(CcData);
string HtmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
string TextContent = null;
string Subject = "My {{params.subject}}";
string ReplyToName = "John Doe";
string ReplyToEmail = "[email protected]";
SendSmtpEmailReplyTo ReplyTo = new SendSmtpEmailReplyTo(ReplyToEmail, ReplyToName);
string AttachmentUrl = null;
string stringInBase64 = "aGVsbG8gdGhpcyBpcyB0ZXN0";
byte[] Content = System.Convert.FromBase64String(stringInBase64);
string AttachmentName = "test.txt";
SendSmtpEmailAttachment AttachmentContent = new SendSmtpEmailAttachment(AttachmentUrl, Content, AttachmentName);
List<SendSmtpEmailAttachment> Attachment = new List<SendSmtpEmailAttachment>();
Attachment.Add(AttachmentContent);
JObject Headers = new JObject();
Headers.Add("Some-Custom-Name", "unique-id-1234");
long? TemplateId = null;
JObject Params = new JObject();
Params.Add("parameter", "My param value");
Params.Add("subject", "New Subject");
List<string> Tags = new List<string>();
Tags.Add("mytag");
SendSmtpEmailTo1 smtpEmailTo1 = new SendSmtpEmailTo1(ToEmail, ToName);
List<SendSmtpEmailTo1> To1 = new List<SendSmtpEmailTo1>();
To1.Add(smtpEmailTo1);
Dictionary<string, object> _parmas = new Dictionary<string, object>();
_parmas.Add("params", Params);
SendSmtpEmailReplyTo1 ReplyTo1 = new SendSmtpEmailReplyTo1(ReplyToEmail, ReplyToName);
SendSmtpEmailMessageVersions messageVersion = new SendSmtpEmailMessageVersions(To1, _parmas, Bcc, Cc, ReplyTo1, Subject);
List<SendSmtpEmailMessageVersions> messageVersiopns = new List<SendSmtpEmailMessageVersions>();
messageVersiopns.Add(messageVersion);
try
{
var sendSmtpEmail = new SendSmtpEmail(Email, To, Bcc, Cc, HtmlContent, TextContent, Subject, ReplyTo, Attachment, Headers, TemplateId, Params, messageVersiopns, Tags);
CreateSmtpEmail result = apiInstance.SendTransacEmail(sendSmtpEmail);
Debug.WriteLine(result.ToJson());
Console.WriteLine(result.ToJson());
Console.ReadLine();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
type herepackage main
import (
"fmt"
"context"
sib_api_v3_sdk "./lib"
)
func main() {
var ctx context.Context
var cli = sib_api_v3_sdk.APIClient{
cfg: sib_api_v3_sdk.NewConfiguration(),
}
//Configure API key authorization: api-key
cli.cfg.AddDefaultHeader("api-key", "YOUR_API_KEY")
sib := sib_api_v3_sdk.NewAPIClient(cli.cfg)
body := SendSmtpEmail{
HtmlContent: "<html><body><h1>This is my first transactional email </h1></body></html",
Subject: "New Subject",
TemplateId: int64(5),
Sender: &SendSmtpEmailSender{
Name: "John Doe"
Email:"[email protected]"
},
To: []string {"[email protected]",},
Cc: []string{"[email protected]",},
Bcc: []string {"[email protected]",},
ReplyTo: SendSmtpEmailReplyTo{
Name: "John Doe"
Email:"[email protected]"
}
Headers: map[string]interface{}{
"Some-Custom-Name":"unique-id-1234",
}
Params: = map[string]interface{}{
"parameter":"My param value",
"subject":"New Subject",
}
}
obj, resp, err := sib.TransactionalEmailsApi.SendTransacEmail(ctx, body)
if err!=nil{
fmt.Println("Error in TransactionalEmailsApi->SendTransacEmail ",err.Error())
return
}
fmt.Println( "SendTransacEmail, response:",resp,"SendTransacEmail object",obj)
return
}
# load the gem
require 'sib-api-v3-sdk'
# setup authorization
SibApiV3Sdk.configure do |config|
# Configure API key authorization: api-key
config.api_key['api-key'] = 'YOUR API KEY'
end
api_instance = SibApiV3Sdk::TransactionalEmailsApi.new
send_smtp_email = SibApiV3Sdk::SendSmtpEmail.new # SendSmtpEmail | Values to send a transactional email
send_smtp_email = {
'subject'=> 'My {{params.subject}}',
'htmlContent'=> '<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>',
'sender'=> {
'name'=> 'John Doe',
'email'=> '[email protected]'
},
'to'=> [{'email'=>'[email protected]','name'=>'John Doe'}],
'cc'=> [{'email'=>'[email protected]','name'=>'Janice Doe'}],
'bcc'=> [{'email'=>'[email protected]','name'=>'Jane Doe'}],
'replyTo'=> {'email'=>'[email protected]','name'=>'John Doe'},
'headers'=> {'Some-Custom-Name'=>'unique-id-1234'},
'params'=> {'parameter'=>'My param value','subject'=>'New Subject'}
}
begin
#Send a transactional email
result = api_instance.send_transac_email(send_smtp_email)
p result
rescue SibApiV3Sdk::ApiError => e
puts "Exception when calling TransactionalEmailsApi->send_transac_email: #{e}"
end
✉️
Send Transactional Emails in PHP
Open Recipe