Send a transactional email

Log in to see full request history
timestatususer agent
Retrieving recent requests…
LoadingLoading…

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": "example@example.com" }; sendSmtpEmail.to = [ { "email": "example@brevo.com", "name": "sample-name" } ]; sendSmtpEmail.replyTo = { "email": "example@brevo.com", "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' => 'contact@brevo.com'], 'replyTo' => ['name' => 'Brevo', 'email' => 'contact@brevo.com'], 'to' => [[ 'name' => 'Max Mustermann', 'email' => 'example@example.com']], '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":"example@example.com"} to = [{"email":"example@example.com","name":"Jane Doe"}] cc = [{"email":"example2@example2.com","name":"Janice Doe"}] bcc = [{"name":"John Doe","email":"example@example.com"}] reply_to = {"email":"replyto@domain.com","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":"example@example.com"}; sendSmtpEmail.to = [{"email":"example@example.com","name":"Jane Doe"}]; sendSmtpEmail.cc = [{"email":"example2@example2.com","name":"Janice Doe"}]; sendSmtpEmail.bcc = [{"name":"John Doe","email":"example@example.com"}]; sendSmtpEmail.replyTo = {"email":"replyto@domain.com","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("example@example.com"); sender.setName("John Doe"); List<SendSmtpEmailTo> toList = new ArrayList<SendSmtpEmailTo>(); SendSmtpEmailTo to = new SendSmtpEmailTo(); to.setEmail("example@example.com"); to.setName("John Doe"); toList.add(to); List<SendSmtpEmailCc> ccList = new ArrayList<SendSmtpEmailCc>(); SendSmtpEmailCc cc = new SendSmtpEmailCc(); cc.setEmail("example1@example.com"); cc.setName("Janice Doe"); ccList.add(cc); List<SendSmtpEmailBcc> bccList = new ArrayList<SendSmtpEmailBcc>(); SendSmtpEmailBcc bcc = new SendSmtpEmailBcc(); bcc.setEmail("example2@example.com"); bcc.setName("John Doe"); bccList.add(bcc); SendSmtpEmailReplyTo replyTo = new SendSmtpEmailReplyTo(); replyTo.setEmail("replyto@domain.com"); 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("example1@example.com"); 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 = "example@example.com"; SendSmtpEmailSender Email = new SendSmtpEmailSender(SenderName, SenderEmail); string ToEmail = "example1@example1.com"; 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 = "example2@example2.com"; SendSmtpEmailBcc BccData = new SendSmtpEmailBcc(BccEmail, BccName); List<SendSmtpEmailBcc> Bcc = new List<SendSmtpEmailBcc>(); Bcc.Add(BccData); string CcName = "John Doe"; string CcEmail = "example3@example2.com"; 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 = "replyto@domain.com"; 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:"example@example.com" }, To: []string {"example@example.com",}, Cc: []string{"example2@example2.com",}, Bcc: []string {"example@example.com",}, ReplyTo: SendSmtpEmailReplyTo{ Name: "John Doe" Email:"example@example.com" } 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'=> 'example@example.com' }, 'to'=> [{'email'=>'example1@example1.com','name'=>'John Doe'}], 'cc'=> [{'email'=>'example2@example2.com','name'=>'Janice Doe'}], 'bcc'=> [{'email'=>'example3@example2.com','name'=>'Jane Doe'}], 'replyTo'=> {'email'=>'replyto@domain.com','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
Body Params

Values to send a transactional email

object

Mandatory if templateId is not passed. Pass name (optional) and email or id of sender from which emails will be sent. name will be ignored if passed along with sender id. For example,
{"name":"Mary from MyShop", "email":"no-reply@myshop.com"}
{"id":2}

array of objects

Mandatory if messageVersions are not passed, ignored if messageVersions are passed
List of email addresses and names (optional) of the recipients. For example,
[{"name":"Jimmy", "email":"jimmy98@example.com"}, {"name":"Joe", "email":"joe@example.com"}]

to
array of objects

List of email addresses and names (optional) of the recipients in bcc

bcc
array of objects

List of email addresses and names (optional) of the recipients in cc

cc
string

HTML body of the message. Mandatory if 'templateId' is not passed, ignored if 'templateId' is passed

string

Plain Text body of the message. Ignored if 'templateId' is passed

string

Subject of the message. Mandatory if 'templateId' is not passed

object

Email (required), along with name (optional), on which transactional mail recipients will be able to reply back. For example,
{"email":"ann6533@example.com", "name":"Ann"}

array of objects

Pass the absolute URL (no local file) or the base64 content of the attachment along with the attachment name. Mandatory if attachment content is passed. For example,
[{"url":"https://attachment.domain.com/myAttachmentFromUrl.jpg", "name":"myAttachmentFromUrl.jpg"}, {"content":"base64 example content", "name":"myAttachmentFromBase64.jpg"}].
Allowed extensions for attachment file:

xlsx, xls, ods, docx, docm, doc, csv, pdf, txt, gif, jpg, jpeg, png, tif, tiff, rtf, bmp, cgm, css, shtml, html, htm, zip, xml, ppt, pptx, tar, ez, ics, mobi, msg, pub, eps, odt, mp3, m4a, m4v, wma, ogg, flac, wav, aif, aifc, aiff, mp4, mov, avi, mkv, mpeg, mpg, wmv, pkpass and xlsm.

If templateId is passed and is in New Template Language format then both attachment url and content are accepted. If template is in Old template Language format, then attachment is ignored

attachment
object

Pass the set of custom headers (not the standard headers) that shall be sent along the mail headers in the original email. 'sender.ip' header can be set (only for dedicated ip users) to mention the IP to be used for sending transactional emails. Headers are allowed in This-Case-Only (i.e. words separated by hyphen with first letter of each word in capital letter), they will be converted to such case styling if not in this format in the request payload. For example,
{"sender.ip":"1.2.3.4", "X-Mailin-custom":"some_custom_header", "idempotencyKey":"abc-123"}.

int64

Id of the template.

object

Pass the set of attributes to customize the template. For example, {"FNAME":"Joe", "LNAME":"Doe"}. It's considered only if template is in New Template Language format.

array of objects

You can customize and send out multiple versions of a mail. templateId can be customized only if global parameter contains templateId. htmlContent and textContent can be customized only if any of the two, htmlContent or textContent, is present in global parameters. Some global parameters such as to(mandatory), bcc, cc, replyTo, subject can also be customized specific to each version.
Total number of recipients in one API request must not exceed 2000. However, you can still pass upto 99 recipients maximum in one message version.
The size of individual params in all the messageVersions shall not exceed 100 KB limit and that of cumulative params shall not exceed 1000 KB.
You can follow this step-by-step guide on how to use messageVersions to batch send emails - https://developers.brevo.com/docs/batch-send-transactional-emails

messageVersions
array of strings

Tag your emails to find them more easily

tags
date-time

UTC date-time on which the email has to schedule (YYYY-MM-DDTHH:mm:ss.SSSZ). Prefer to pass your timezone in date-time format for scheduling. There can be an expected delay of +5 minutes in scheduled email delivery.

string

Valid UUIDv4 batch id to identify the scheduled batches transactional email. If not passed we will create a valid UUIDv4 batch id at our end.

Responses

Language
Credentials
Click Try It! to start a request and see the response here! Or choose an example:
application/json