Attachments
Each item in the attachments array must include:
- •
filename(string, required): Name the recipient sees, including extension. - •
content(string): Base64-encoded file content. Use this when sending generated files (PDFs, CSVs, images). - •
path(string): Absolute server file path. Use only if your app runs on the same server as the API.
At least one of content or path is required per attachment. Maximum 10 attachments per request. The combined decoded size of all attachments must not exceed 25 MB; requests over this limit are rejected with 400 Bad Request.
Blocked file types
To protect recipients, Altermail rejects attachments with harmful or potentially malicious file extensions. Requests containing any blocked type will return a 400 error.
.exe .dll .bat .cmd .com .msi .msp .ps1 .psm1 .psd1 .vbs .vbe .js .jse .wsf .wsh .scr .pif .hta .cpl .jar .reg .inf .lnk .iso .img
Use safe, widely-supported formats such as .pdf, .png, .jpg, .csv, or .docx for your attachments.
curl -X POST https://api.altermail-console.com.ng/v1/user/email/send \
-H "Content-Type: application/json" \
-H "token: YOUR_API_KEY" \
-d '{
"email": "recipient@example.com",
"fromEmail": "billing@yourdomain.com",
"subject": "Your invoice #1042",
"mailBodyHtml": "<p>Please find your invoice attached.</p>",
"attachments": [
{
"filename": "invoice-1042.pdf",
"content": "BASE64_ENCODED_FILE_CONTENT"
}
]
}'import fs from "fs";
const pdfContent = fs.readFileSync("invoice-1042.pdf").toString("base64");
await fetch("https://api.altermail-console.com.ng/v1/user/email/send", {
method: "POST",
headers: { "Content-Type": "application/json", "token": "YOUR_API_KEY" },
body: JSON.stringify({
email: "recipient@example.com",
fromEmail: "billing@yourdomain.com",
subject: "Your invoice #1042",
mailBodyHtml: "<p>Please find your invoice attached.</p>",
attachments: [
{ filename: "invoice-1042.pdf", content: pdfContent },
],
}),
});import base64
with open("invoice-1042.pdf", "rb") as f:
pdf_b64 = base64.b64encode(f.read()).decode()
requests.post("https://api.altermail-console.com.ng/v1/user/email/send",
headers={"Content-Type": "application/json", "token": "YOUR_API_KEY"},
json={
"email": "recipient@example.com",
"fromEmail": "billing@yourdomain.com",
"subject": "Your invoice #1042",
"mailBodyHtml": "<p>Please find your invoice attached.</p>",
"attachments": [
{"filename": "invoice-1042.pdf", "content": pdf_b64}
],
},
)$content = base64_encode(file_get_contents("invoice-1042.pdf"));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"email" => "recipient@example.com",
"fromEmail" => "billing@yourdomain.com",
"subject" => "Your invoice #1042",
"mailBodyHtml" => "<p>Please find your invoice attached.</p>",
"attachments" => [
["filename" => "invoice-1042.pdf", "content" => $content],
],
]));import "encoding/base64"
import "os"
data, _ := os.ReadFile("invoice-1042.pdf")
b64 := base64.StdEncoding.EncodeToString(data)
json.Marshal(map[string]any{
"email": "recipient@example.com",
"fromEmail": "billing@yourdomain.com",
"subject": "Your invoice #1042",
"mailBodyHtml": "<p>Please find your invoice attached.</p>",
"attachments": []map[string]string{
{"filename": "invoice-1042.pdf", "content": b64},
},
})using System.IO;
var fileBytes = File.ReadAllBytes("invoice-1042.pdf");
var b64 = Convert.ToBase64String(fileBytes);
var payload = new {
email = "recipient@example.com",
fromEmail = "billing@yourdomain.com",
subject = "Your invoice #1042",
mailBodyHtml = "<p>Please find your invoice attached.</p>",
attachments = new[] {
new { filename = "invoice-1042.pdf", content = b64 }
},
};
var response = await client.PostAsJsonAsync("https://api.altermail-console.com.ng/v1/user/email/send", payload);import java.util.Base64;
import java.nio.file.*;
var pdf = Base64.getEncoder().encodeToString(
Files.readAllBytes(Path.of("invoice-1042.pdf"))
);
var body = String.format("""
{
"email": "recipient@example.com",
"fromEmail": "billing@yourdomain.com",
"subject": "Your invoice #1042",
"mailBodyHtml": "<p>Please find your invoice attached.</p>",
"attachments": [{"filename": "invoice-1042.pdf", "content": "%s"}]
}
""", pdf);#include <curl/curl.h>
#include <fstream>
#include <string>
// Use OpenSSL or a base64 library to encode the file:
// std::string b64 = base64Encode(readFile("invoice-1042.pdf"));
// Build JSON manually with the encoded content
std::string payload =
"{\"email\":\"recipient@example.com\","
"\"fromEmail\":\"billing@yourdomain.com\","
"\"subject\":\"Your invoice #1042\","
"\"mailBodyHtml\":\"<p>Please find your invoice attached.</p>\","
"\"attachments\":[{\"filename\":\"invoice-1042.pdf\",\"content\":\"" + b64 + "\"}]}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());