Mailhub
  • Welcome
  • Introduction
  • Get your API key
  • Connect your domain
  • Create layouts & pages
  • Send email
  • Internationalization
  • Editor
    • Insert page into a layout
    • Dynamic Expressions
Powered by GitBook
On this page

Send email

Send email through API

POST https://api.mailhub.sh/v1/send

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Body

Name
Type
Required
Comment

from

string

Yes

to

string | string[]

Yes

subject

string

Yes

bcc

string[]

No

cc

string[]

No

reply_to

string[]

No

layout_identifier

string

Yes/No

Layout or page identifier

Eg. tp-xxxxxx Can't be used with code parameter

code

string

Yes/No

HTML Code you want to send Can't be used with layout_identifier parameter

text

string

No

tags

object[]

No

language

string

No

attachments

object[]

No

Example (payload)

{
  "layout_identifier": "string", // The identifier of the layout used for generating the email (e.g., "welcome-email")
  "language": "string", // ISO language code, e.g., "en", "fr"
  "variables": { 
    "name": "John Doe"
    // Any dynamic variables used in the template (e.g., { "order_id": "12345" })
  },
  "code": null, // Always null when using layout_identifier; can contain raw HTML if no layout is used (Tailwind compatible)
  "from": "string", // Sender email address
  "to": "string", // Recipient email address
  "subject": "string" // Email subject line
}

Example (request)

curl -X POST "https://api.mailhub.sh/v1/send" \
  --header "Authorization: Bearer <<YOUR_API_KEY_HERE>>" \
  --header "Content-Type: application/json" \
  --data '{
      "layout_identifier": "<<YOUR_LAYOUT_ID>>",
      "variables": {},
      "code": null,
      "from": "Example <example@your-domain.com>",
      "to": "example@mailhub.sh",
      "subject": "hello world",
      ...
  }'
fetch(`https://api.mailhub.sh/v1/send`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer <<YOUR_API_KEY_HERE>>',
    },
    body: JSON.stringify({
        layout_identifier: '<<YOUR_LAYOUT_ID>>',
        variables: {},
        code: null,
        from: 'Example <example@your-domain.com>',
        to: 'example@mailhub.sh',
        subject: 'hello world',
        ...
    }),
})
    .then((data) => {
        console.log(data);
    })
    .catch((error) => {
        console.error('Error:', error);
    });
var message = new
{
    layout_identifier = "<<YOUR_LAYOUT_ID>>",
    variables = new { },
    from = "Example <example@your-domain.com>",
    to = "example@mailhub.sh",
    subject = "hello world"
};


RestClient client = new RestClient();
RestRequest request = new RestRequest("https://api.mailhub.sh/v1/send", Method.Post);
request.AddHeader("Authorization", $"Bearer <<YOUR_API_KEY_HERE>>");

request.AddJsonBody(msg, "application/json");

var response = client.Execute(request);
<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$url = "https://api.mailhub.sh/v1/send";

$data = [
    'layout_identifier' => '<<YOUR_LAYOUT_ID>>',
    'variables' => [],
    'code' => null,
    'from' => 'Example <example@your-domain.com>',
    'to' => 'example@mailhub.sh',
    'subject' => 'hello world'
];

$headers = [
    "Content-Type" => "application/json",
    "Authorization" => "Bearer <<YOUR_API_KEY_HERE>>"
];

try {
    $response = $client->post($url, [
        'headers' => $headers,
        'json' => $data
    ]);

    $responseBody = $response->getBody();
    $decodedResponse = json_decode($responseBody, true);

    print_r($decodedResponse);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>
PreviousCreate layouts & pagesNextInternationalization

Last updated 3 months ago

Language code (eg. en, en_gb, en_au, ...)

{
    name: string
}
{
    filename: string, // (optional)
    content: string | Buffer, //(optional)
    path: string, //(optional)
    contentType: string, //(optional)
}
Documentation