gitlabEdit

๐Ÿ“งEmail Dispatch

Learn how to send emails with document attachments through Docs-Dispatcher's email service.

Overview

This recipe covers:

  1. Sending emails via SMTP providers

  2. Attaching generated documents

  3. Template-based email content

  4. CC/BCC recipients

  5. HTML and plain text emails

  6. Complete examples in 4 languages

What You'll Learn

  • Structure email dispatch requests

  • Attach documents from templates

  • Configure SMTP providers

  • Handle multiple recipients

  • Email composition best practices

  • Complete working examples

Prerequisites

  • Docs-Dispatcher account with JWT

  • SMTP provider configured (Gmail, SendGrid, AWS SES, custom SMTP)

  • Email template created (optional)

  • Basic REST API knowledge

Email Service Overview

The email service supports:

  • โœ… SMTP providers (Gmail, SendGrid, AWS SES, Mailgun, custom)

  • โœ… Document attachments from templates

  • โœ… HTML and plain text content

  • โœ… CC and BCC recipients

  • โœ… Reply-to addresses

  • โœ… Custom headers

  • โœ… Template-based content

Step 1: Authentication

Dispatcher API uses HTTP Basic Authentication. You'll need your Dispatcher account email and password for all API calls.

Setup Credentials

circle-info

No token management needed! Unlike JWT-based APIs, Basic Auth doesn't require separate authentication endpoints or token refresh. Your credentials are sent with each request.

Quick links:

Step 2: Prepare Email Request

Basic Email Structure

Required Fields

Field
Type
Description

providerName

string

SMTP provider: sendgrid, ses, gmail, smtp

email.from

object

Sender email and name

email.to

array

Recipient email(s)

email.subject

string

Email subject line

email.body

object

HTML and/or text content

Optional Fields

Field
Type
Description

email.cc

array

CC recipients

email.bcc

array

BCC recipients

email.replyTo

object

Reply-to address

email.attachments

array

File attachments

template.id

number

Template for document attachment

Step 3: Email with Document Attachment

Attach Generated Document

Success Response:

Step 4: Multiple Recipients (CC/BCC)

Email with CC and BCC

Complete Examples

curl (Complete Flow)

Node.js (Complete Flow)

PHP (Complete Flow)

Java (Complete Flow)

Provider-Specific Notes

SendGrid

Provider name: sendgrid

Features:

  • High deliverability

  • Email tracking

  • Click/open analytics

  • Template support

Configuration:

  • API key required

  • Verified sender identity

AWS SES

Provider name: ses

Features:

  • Low cost

  • High volume support

  • Email reputation monitoring

Configuration:

  • AWS credentials required

  • Domain verification needed

Gmail

Provider name: gmail

Features:

  • Easy setup

  • Good for small volumes

  • App password required

Configuration:

  • App-specific password

  • 2FA recommended

Best Practices

1. Use Plain Text Alternative

Always provide both HTML and plain text:

2. Validate Email Addresses

3. Set Reply-To

Error Handling

Common Errors

Invalid Recipient

Provider Error

Next Steps

Core Concepts

Summary

You've learned:

  • โœ… Send emails with document attachments

  • โœ… Configure SMTP providers

  • โœ… Handle multiple recipients

  • โœ… Complete implementations in 4 languages

Email dispatch makes document delivery seamless!

Last updated