string
sendEmail is the primary method for submitting messages through the BosonMail API. It accepts a recipient list, a subject, and a body object that can contain text, HTML, CC, BCC, and attachments. The method always resolves, even on failure, and returns a Result object that tells you whether the API accepted the message.
Signature
Parameters
string | string[]
required
Primary recipient(s). A single email address or an array of addresses. Must contain at least one non-empty string after trimming. The SDK does not validate email address format; the API checks that server-side.
string
required
Email subject line. Must be a non-empty string after trimming.
SendEmailBody
required
The email content and optional fields.
SendEmailBody fields
Plain text content. Either
text or html (or both) must be provided as a non-empty string after trimming.string
HTML content. Either
text or html (or both) must be provided as a non-empty string after trimming.string | string[]
Carbon-copy recipients. Accepts a single address or an array.
string | string[]
Blind carbon-copy recipients. Accepts a single address or an array.
SendAttachment[]
File attachments. When present, the request switches to
multipart/form-data. See Attachments for full details.Return value
boolean
required
true when the API accepted the email. false for any validation, network, API, or timeout failure.string
Human-readable description when
success is false.number
HTTP status code from the API response. Absent for client-side validation errors and network/timeout failures.
string
BosonMail message ID, returned as a string when present in the API response.
string
API message identifier. May be
undefined even on success, so always check it before calling getEmailStatus.EmailSentStatus
Initial status from the API. Defaults to
"queued" when the API omits it.Transport: JSON vs multipart
The SDK chooses the request format automatically:- No attachments:
Content-Type: application/json,POST /emails/send. Body fieldsto,cc,bccare joined with,(no space) when arrays. - With attachments:
multipart/form-data(boundary set byfetch),POST /emails/send. Fields:to,subject,textContent,htmlContent,cc,bcc, and oneattachmentsfield per file. Array fields are joined with,(comma + space) after trimming each element.
The SDK does not set the
Content-Type header for multipart requests; fetch handles the boundary automatically.Client-side validation
Before any network request, the SDK validates the input. These errors return{ success: false, errorMessage } with no statusCode:
What success means
A successfulsendEmail means the BosonMail API accepted the message. The typical initial status is "queued". It does not mean the email has been delivered, read, or that the recipient address is valid. Use getEmailStatus to track delivery progress.
Examples
Plain text email
HTML email with CC
send-html-cc.ts
With attachments
send-with-attachments.ts
HTML emails
Best practices for HTML content, multipart compatibility, and escaping user input.
Attachments
Supported content types, size limits, and security considerations.
Multiple recipients
How arrays are serialized and when to send individual emails instead.
Error handling
How to classify failures and decide when to retry.