### Install and Start Redis using Homebrew
Source: https://learn.emailengine.app/docs/installation/macos
Installs Homebrew if not present, then installs and starts the Redis service. Verify the Redis connection with 'redis-cli ping'.
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
```bash
brew install redis
```
```bash
brew services start redis
```
```bash
redis-cli ping
```
--------------------------------
### Production Setup: Install Dependencies and EmailEngine
Source: https://learn.emailengine.app/docs/deployment/systemd
Commands to set up a production environment, including installing Redis, downloading, and installing the EmailEngine binary.
```bash
sudo apt update
sudo apt install -y redis-server
# Download and install EmailEngine
wget https://go.emailengine.app/emailengine.tar.gz
tar xzf emailengine.tar.gz
sudo mv emailengine /usr/local/bin/
sudo chmod +x /usr/local/bin/emailengine
```
--------------------------------
### Install Redis Server on Ubuntu/Debian
Source: https://learn.emailengine.app/docs/installation/linux
Install the Redis server package using apt. Ensure Redis is started and enabled to run on boot. Verify the installation by pinging the Redis CLI.
```bash
sudo apt update
sudo apt install redis-server
# Start and enable Redis
sudo systemctl start redis-server
sudo systemctl enable redis-server
# Verify
redis-cli ping
```
--------------------------------
### Start Promtail Service
Source: https://learn.emailengine.app/docs/advanced/logging
This command starts the Promtail service using the specified configuration file. Ensure Promtail is installed and the config file is correctly placed.
```bash
promtail -config.file=promtail-config.yml
```
--------------------------------
### Install EmailEngine Binary
Source: https://learn.emailengine.app/docs/getting-started/quick-start
Download and run the EmailEngine binary for a quick setup. Ensure Redis is accessible.
```bash
# Download latest release
$ wget https://go.emailengine.app/emailengine.tar.gz
$ tar xzf emailengine.tar.gz
$ chmod +x emailengine
# Start EmailEngine (default Redis database is 8)
$ ./emailengine --dbs.redis="redis://127.0.0.1:6379/8"
```
--------------------------------
### Install Redis in WSL2
Source: https://learn.emailengine.app/docs/installation/windows
Steps to install and start the Redis server within the Windows Subsystem for Linux (WSL2). This involves updating package lists, installing redis-server, and starting the service.
```bash
wsl
sudo apt update
sudo apt install redis-server
sudo service redis-server start
exit
```
--------------------------------
### Expose Local Server with ngrok for Webhook Testing
Source: https://learn.emailengine.app/docs/reference/webhook-events
This example shows the command-line steps to start a local Node.js server and then expose it to the internet using ngrok. The ngrok URL can then be configured in EmailEngine to test webhook delivery to your local environment.
```bash
# Start local server
node server.js
# Expose via ngrok
ngrok http 3000
# Use ngrok URL in EmailEngine webhook settings
https://abc123.ngrok.io/webhook
```
--------------------------------
### Complete Email Automation Example in PHP
Source: https://learn.emailengine.app/docs/integrations/php
This example demonstrates how to set up an EmailEngine client, register an email account, send an email, and retrieve unread messages. Ensure you have the EmailEngine PHP SDK installed via Composer.
```php
ee = new EmailEngine([
'access_token' => $token,
'ee_base_url' => $baseUrl,
]);
}
public function registerAccount($accountId, $email, $password, $imapHost, $smtpHost)
{
try {
$response = $this->ee->request('post', '/v1/account', [
'account' => $accountId,
'name' => $email,
'email' => $email,
'imap' => [
'auth' => ['user' => $email, 'pass' => $password],
'host' => $imapHost,
'port' => 993,
'secure' => true,
],
'smtp' => [
'auth' => ['user' => $email, 'pass' => $password],
'host' => $smtpHost,
'port' => 465,
'secure' => true,
],
]);
return $this->waitForConnection($accountId);
} catch (Exception $e) {
error_log("Failed to register account: " . $e->getMessage());
return false;
}
}
private function waitForConnection($accountId, $maxWait = 60)
{
$startTime = time();
while (time() - $startTime < $maxWait) {
$info = $this->ee->request('get', "/v1/account/$accountId");
if ($info['state'] === 'connected') {
return true;
}
if (in_array($info['state'], ['authenticationError', 'connectError'])) {
error_log("Account connection failed: " . $info['state']);
return false;
}
sleep(2);
}
error_log("Account connection timeout");
return false;
}
public function sendEmail($accountId, $to, $subject, $body)
{
try {
$response = $this->ee->request('post', "/v1/account/$accountId/submit", [
'to' => [['address' => $to]],
'subject' => $subject,
'html' => $body,
]);
return $response['messageId'];
} catch (Exception $e) {
error_log("Failed to send email: " . $e->getMessage());
return false;
}
}
public function getUnreadMessages($accountId)
{
try {
// Use POST search endpoint to filter by unseen messages
$response = $this->ee->request('post', "/v1/account/$accountId/search?path=INBOX", [
'search' => [
'unseen' => true,
],
]);
return $response['messages'];
} catch (Exception $e) {
error_log("Failed to get messages: " . $e->getMessage());
return [];
}
}
}
// Usage
$automation = new EmailAutomation(
'your-api-token',
'http://127.0.0.1:3000/'
);
// Register account
if ($automation->registerAccount(
'my-account',
'user@example.com',
'password',
'imap.example.com',
'smtp.example.com'
)) {
echo "Account registered successfully\n";
// Send email
$messageId = $automation->sendEmail(
'my-account',
'recipient@example.com',
'Hello from PHP',
'
This is a test email
'
);
if ($messageId) {
echo "Email sent: $messageId\n";
}
// Check unread messages
$messages = $automation->getUnreadMessages('my-account');
echo "Unread messages: " . count($messages) . "\n";
}
```
--------------------------------
### Install Caddy Web Server
Source: https://learn.emailengine.app/docs/installation/linux
Installs the Caddy web server by adding its repository and then installing the package using apt.
```bash
# Add Caddy repository
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
```
--------------------------------
### Complete Systemd Service File Example
Source: https://learn.emailengine.app/docs/deployment/systemd
A comprehensive systemd service file for EmailEngine including unit, service, and install sections with memory management and restart policies.
```ini
[Unit]
Description=EmailEngine Email API Service
After=network.target redis.service
Requires=redis.service
[Service]
Type=simple
User=emailengine
Group=emailengine
WorkingDirectory=/opt/emailengine
ExecStart=/usr/local/bin/emailengine
# Memory management - kill and restart when exceeded
MemoryMax=4G
# Restart policy
Restart=always # Always restart (including after OOM kill)
RestartSec=5 # Wait 5 seconds before restart
StartLimitInterval=300 # Rate limit: max restarts within 5 minutes
StartLimitBurst=5 # Max 5 restarts within interval
# Environment
Environment="EENGINE_REDIS=redis://localhost:6379/8"
Environment="EENGINE_SECRET=your-secret-key-at-least-32-characters"
StandardOutput=journal
StandardError=journal
SyslogIdentifier=emailengine
[Install]
WantedBy=multi-user.target
```
--------------------------------
### Complete EmailEngine Production TOML Configuration Example
Source: https://learn.emailengine.app/docs/configuration/cli
An example of a complete TOML configuration file for a production EmailEngine setup, including database and API settings.
```toml
# /etc/emailengine/production.toml
# Database configuration
[dbs]
redis = "redis://redis-cluster.example.com:6379"
```
--------------------------------
### Test EmailEngine Installation
Source: https://learn.emailengine.app/docs/installation/source
Starts the EmailEngine server and verifies the installation by sending a health check request. Ensure you have another terminal available for the curl command. Press Ctrl+C to stop the server.
```bash
cd /opt/emailengine
node app/server.js
```
```bash
curl http://localhost:3000/health
```
--------------------------------
### Start EmailEngine using SystemD
Source: https://learn.emailengine.app/docs/advanced/encryption
Start the EmailEngine service using SystemD.
```bash
sudo systemctl start emailengine
```
--------------------------------
### C# HttpClient Example for Listing Account Tokens
Source: https://learn.emailengine.app/docs/api/get-v-1-tokens-account-account
Demonstrates how to use HttpClient in C# to make a GET request to the list account tokens endpoint. Includes setting headers for authorization and content type.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/tokens/account/:account");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Install EmailEngine using Install Script (Ubuntu/Debian)
Source: https://learn.emailengine.app/docs/deployment/systemd
Download and execute the provided install script for Ubuntu/Debian systems to install EmailEngine. Verify the installation afterwards.
```bash
# Download and run install script
wget https://go.emailengine.app -O install.sh
chmod +x install.sh
sudo ./install.sh
# Verify installation
emailengine --version
```
--------------------------------
### Example Token Outputs
Source: https://learn.emailengine.app/docs/configuration/prepared-settings/tokens
Example outputs for token generation and export commands.
```bash
f05d76644ea39c4a2ee33e7bffe55808b716a34b51d67b388c7d60498b0f89bc
```
```bash
hKJpZNlAMzAxZThjNTFhZjgxM2Q3MzUxNTYzYTFlM2I1NjVkYmEzZWJjMzk4ZjI4OWZjNjgzN...
```
--------------------------------
### Start EmailEngine using Docker
Source: https://learn.emailengine.app/docs/advanced/encryption
Start the EmailEngine container using Docker.
```bash
docker start emailengine
```
--------------------------------
### Install EmailEngine in WSL2 (Manual)
Source: https://learn.emailengine.app/docs/installation/windows
Manual installation steps for EmailEngine within WSL2. This involves updating package lists, installing Redis, downloading and extracting the EmailEngine tarball, and moving the binary to the system path.
```bash
# Or manual installation
sudo apt update
sudo apt install redis-server
wget https://go.emailengine.app/emailengine.tar.gz
tar xzf emailengine.tar.gz
sudo mv emailengine /usr/local/bin/
```
--------------------------------
### Start and Enable Caddy Service
Source: https://learn.emailengine.app/docs/installation/linux
Enables Caddy to start on boot and starts the Caddy service. It also shows how to check the service status.
```bash
sudo systemctl enable caddy
sudo systemctl start caddy
sudo systemctl status caddy
```
--------------------------------
### Install EmailEngine from Source
Source: https://learn.emailengine.app/docs/deployment/systemd
Steps to install EmailEngine from its source distribution. This involves downloading the source, installing Node.js dependencies, and linking the package globally. Verify the installation with the version command.
```bash
# Download source distribution
wget https://go.emailengine.app/source-dist.tar.gz
tar xzf source-dist.tar.gz
cd emailengine
# Install dependencies
npm install --omit=dev
# Make globally available
sudo npm link
# Verify installation
emailengine --version
```
--------------------------------
### Enable and Start SystemD Service
Source: https://learn.emailengine.app/docs/installation/source
Reload the systemd daemon, enable the EmailEngine service to start on boot, and then start the service. Finally, check its status.
```bash
sudo systemctl daemon-reload
sudo systemctl enable emailengine
sudo systemctl start emailengine
sudo systemctl status emailengine
```
--------------------------------
### Create Test Account with Multiple Sub-connections
Source: https://learn.emailengine.app/docs/advanced/inbox-placement-testing
This example demonstrates creating a test account and configuring multiple sub-connections to monitor both the Junk and Trash folders simultaneously.
```bash
curl -XPOST "http://localhost:3000/v1/account" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"account": "test-account",
"email": "test@ethereal.email",
"imap": {
"host": "imap.ethereal.email",
"port": 993,
"secure": true,
"auth": {
"user": "test@ethereal.email",
"pass": "password123"
}
},
"subconnections": [
"\\Junk",
"\\Trash"
]
}'
```
--------------------------------
### Create .env file and start EmailEngine
Source: https://learn.emailengine.app/docs/configuration/environment-variables
Demonstrates how to create a .env file with Redis and secret configurations and then start EmailEngine, which automatically loads these variables.
```bash
# Create .env file
echo "EENGINE_REDIS=redis://localhost:6379" > .env
echo "EENGINE_SECRET=$(openssl rand -hex 32)" >> .env
# Start EmailEngine (will load .env automatically)
emailengine
```
--------------------------------
### Run Automated Installer
Source: https://learn.emailengine.app/docs/installation/linux
Make the installer script executable and run it with sudo. Provide your domain name as an argument, or leave it empty for auto-generation. An optional version number can be specified.
```bash
chmod +x install.sh
sudo su
./install.sh example.com
```
```bash
./install.sh example.com 2.55.4
```
--------------------------------
### Install Redis Server on CentOS/RHEL
Source: https://learn.emailengine.app/docs/installation/linux
Install the Redis server package using yum. Ensure Redis is started and enabled to run on boot.
```bash
sudo yum install redis
sudo systemctl start redis
sudo systemctl enable redis
```
--------------------------------
### Get Queued Message Example
Source: https://learn.emailengine.app/docs/api/get-v-1-outbox-queueid
This example demonstrates how to retrieve a queued message using its queueId. Ensure you replace ':queueId' with the actual identifier.
```http
GET https://emailengine.example.com/v1/outbox/:queueId
```
--------------------------------
### Start Redis Server with Configuration File
Source: https://learn.emailengine.app/docs/configuration/redis
Launch the Redis server using a specified configuration file.
```bash
redis-server /etc/redis/redis.conf
```
--------------------------------
### Start Filebeat Service
Source: https://learn.emailengine.app/docs/advanced/logging
These commands start and enable the Filebeat service to begin shipping logs. Ensure Filebeat is installed and configured correctly before running these commands.
```bash
sudo systemctl start filebeat
sudo systemctl enable filebeat
```
--------------------------------
### Production Setup: Create User and Directories
Source: https://learn.emailengine.app/docs/deployment/systemd
Commands to create a dedicated system user for EmailEngine and necessary directories for logs and configuration. Ensure correct ownership and permissions are set.
```bash
sudo useradd --system --home /opt/emailengine --shell /bin/false emailengine
sudo mkdir -p /etc/emailengine /var/log/emailengine
sudo chown emailengine:emailengine /var/log/emailengine
```
--------------------------------
### Create Configuration and Log Directories
Source: https://learn.emailengine.app/docs/deployment/systemd
Set up the necessary directories for EmailEngine configuration and logs, and assign ownership to the dedicated EmailEngine user.
```bash
# Create directories
sudo mkdir -p /etc/emailengine
sudo mkdir -p /var/log/emailengine
# Set permissions
sudo chown emailengine:emailengine /etc/emailengine
sudo chown emailengine:emailengine /var/log/emailengine
```
--------------------------------
### C# HttpClient Example
Source: https://learn.emailengine.app/docs/api/get-v-1-changes
Example of how to make a GET request to the /v1/changes endpoint using C#'s HttpClient. This code retrieves and prints the response content.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/changes");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Configure Runtime Settings at Startup
Source: https://learn.emailengine.app/docs/reference/configuration-options
Apply runtime settings at startup by setting the EENGINE_SETTINGS environment variable to a JSON string. This example configures the service URL, webhook endpoint, and enables webhooks.
```bash
EENGINE_SETTINGS='{"serviceUrl":"https://emailengine.example.com","webhooks":"https://your-app.com/webhooks","webhooksEnabled":true}'
```
--------------------------------
### C# HttpClient Example
Source: https://learn.emailengine.app/docs/api/get-v-1-autoconfig
Example of how to make a GET request to the autoconfig endpoint using HttpClient in C#. Ensure you replace "" with your actual access token.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/autoconfig");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### List Gateways Request Example
Source: https://learn.emailengine.app/docs/api/get-v-1-gateways
This example demonstrates how to make a GET request to the /v1/gateways endpoint to retrieve a list of registered gateways. It includes query parameters for pagination and header parameters for timeouts and authorization.
```http
GET
## https://emailengine.example.com/v1/gateways
```
```json
{
"total": 120,
"page": 0,
"pages": 24,
"gateways": [
{
"gateway": "example",
"name": "My Email Gateway",
"deliveries": 100,
"lastUse": "2021-02-17T13:43:18.860Z",
"lastError": {
"response": "Token request failed for gmail (refresh_token, HTTP 400): invalid_grant - Token has been expired or revoked.",
"serverResponseCode": "OauthRenewError",
"tokenRequest": {
"grant": "refresh_token",
"provider": "gmail",
"status": 400,
"clientId": "1023289917884-h3nu00e9cb7h252e24c23sv19l8k57ah.apps.googleusercontent.com",
"scopes": [
"https://mail.google.com/"
],
"response": {
"error": "invalid_grant",
"error_description": "Bad Request"
}
}
}
}
]
}
```
--------------------------------
### Set up WireGuard VPN Server
Source: https://learn.emailengine.app/docs/deployment/security
Example configuration for setting up a WireGuard VPN server on Ubuntu/Debian. This includes generating keys and configuring the server interface.
```bash
sudo apt install wireguard
# Generate keys
wg genkey | tee privatekey | wg pubkey > publickey
# Configure /etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.1/24
PrivateKey =
ListenPort = 51820
[Peer]
PublicKey =
AllowedIPs = 10.0.0.2/32
```
--------------------------------
### Set Prepared License via Environment Variable (Basic)
Source: https://learn.emailengine.app/docs/configuration/prepared-settings/license
Use the EENGINE_PREPARED_LICENSE environment variable to provide a license key for automated activation on startup. This is the simplest method for prepared licensing.
```bash
export EENGINE_PREPARED_LICENSE="your-license-key-here"
emailengine
```
--------------------------------
### Example: Route by Account - Customer A Filter
Source: https://learn.emailengine.app/docs/webhooks/webhook-routing
This filter function routes webhooks specifically for accounts starting with 'customer-a-'.
```javascript
// Filter: Only Customer A's accounts
if (payload.account.startsWith('customer-a-')) {
return true;
}
```
--------------------------------
### Example .env file for Development
Source: https://learn.emailengine.app/docs/configuration
A sample .env.example file to commit to version control, showing required environment variables for development. It includes placeholders for secrets and notes on generating password hashes.
```bash
# .env.example (commit this)
EENGINE_HOST=0.0.0.0
EENGINE_PORT=3000
REDIS_URL=redis://localhost:6379
# Generate hash: emailengine password -p "your-password" --hash
EENGINE_PREPARED_PASSWORD=JHBia2RmMi1zaGE1MTIk...
```
--------------------------------
### Create EmailEngine Directories
Source: https://learn.emailengine.app/docs/installation/source
Sets up the necessary directory structure for EmailEngine. Ensure you have sudo privileges for this operation.
```bash
sudo mkdir -p /opt/emailengine/app
cd /opt/emailengine
```
--------------------------------
### Get OAuth2 Access Token Example
Source: https://learn.emailengine.app/docs/api/get-v-1-account-account-oauthtoken
This example demonstrates the structure of a successful JSON response when retrieving an OAuth2 access token. It includes the account identifier, user, the generated access token, and the associated OAuth2 provider.
```json
{
"account": "user123",
"user": "user@example.com",
"accessToken": "aGVsbG8gd29ybGQ=",
"provider": "gmail"
}
```
--------------------------------
### Download and Run EmailEngine from Source
Source: https://learn.emailengine.app/docs/installation
Downloads the source distribution, extracts it, navigates into the directory, and starts the server. Requires Node.js 20+.
```bash
# Source: Production deployment
wget https://go.emailengine.app/source-dist.tar.gz
tar xzf source-dist.tar.gz && cd emailengine
node server.js
```
--------------------------------
### Example: Route by Account - Customer B Filter
Source: https://learn.emailengine.app/docs/webhooks/webhook-routing
This filter function routes webhooks specifically for accounts starting with 'customer-b-'.
```javascript
// Filter: Only Customer B's accounts
if (payload.account.startsWith('customer-b-')) {
return true;
}
```
--------------------------------
### Example cURL Request to List Accounts
Source: https://learn.emailengine.app/docs/api-reference
A cURL command to make a GET request to the accounts endpoint. Replace YOUR_ACCESS_TOKEN with your actual token.
```curl
curl http://localhost:3000/v1/accounts \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
--------------------------------
### Setup and Manage EmailEngine SystemD Service
Source: https://learn.emailengine.app/docs/installation/linux
Creates the system user for EmailEngine, reloads systemd, enables and starts the EmailEngine service, and checks its status.
```bash
# Create user
sudo useradd --system --home /opt/emailengine --shell /bin/false emailengine
# Enable and start
sudo systemctl daemon-reload
sudo systemctl enable emailengine
sudo systemctl start emailengine
sudo systemctl status emailengine
```
--------------------------------
### C# HttpClient Example
Source: https://learn.emailengine.app/docs/api/get-v-1-gateway-gateway
This C# code snippet demonstrates how to make a GET request to the gateway endpoint using HttpClient, including setting the authorization header.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/gateway/:gateway");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Download and Install EmailEngine Binary
Source: https://learn.emailengine.app/docs/deployment/systemd
Use this command to download the EmailEngine binary, extract it, move it to the system's PATH, and make it executable. Verify the installation with the version command.
```bash
# Download and extract
wget https://go.emailengine.app/emailengine.tar.gz
tar xzf emailengine.tar.gz
sudo mv emailengine /usr/local/bin/
sudo chmod +x /usr/local/bin/emailengine
# Verify installation
emailengine --version
```
--------------------------------
### Get Export Status Response Example
Source: https://learn.emailengine.app/docs/api/get-v-1-account-account-export-exportid
This JSON object represents a successful response from the export status endpoint, detailing the job's progress and metadata.
```json
{
"exportId": "exp_abc123def456abc123def456",
"status": "processing",
"phase": "indexing",
"folders": [
"string"
],
"startDate": "2024-01-01T00:00:00Z",
"endDate": "2024-12-31T23:59:59Z",
"isEncrypted": false,
"progress": {
"foldersScanned": 1,
"foldersTotal": 2,
"messagesQueued": 1500,
"messagesExported": 500,
"messagesSkipped": 5,
"bytesWritten": 52428800
},
"created": "2024-01-15T10:30:00Z",
"expiresAt": "2024-01-16T10:30:00Z",
"truncated": true,
"error": "string"
}
```
--------------------------------
### Integrate New Relic APM
Source: https://learn.emailengine.app/docs/advanced/monitoring
Monitor EmailEngine with New Relic APM by installing the agent, configuring `newrelic.js`, and starting your Node.js application with the New Relic agent.
```bash
# Install agent
npm install newrelic
# Configure newrelic.js
# Start with agent
node -r newrelic server.js
```
--------------------------------
### Example n8n Workflow Structure
Source: https://learn.emailengine.app/docs/integrations/low-code
Illustrates a typical workflow in n8n, starting with a webhook and branching to multiple outputs like notifications, database storage, or API calls.
```bash
Webhook → IF (check conditions) → Multiple outputs:
├─→ Send Telegram notification
├─→ Save to PostgreSQL
└─→ Call API endpoint
```
--------------------------------
### Load Production License Key from File
Source: https://learn.emailengine.app/docs/reference/configuration-options
Set the EENGINE_PREPARED_LICENSE environment variable by reading the license key from a file. This is the recommended method for production environments.
```bash
# From file
EENGINE_PREPARED_LICENSE="$(cat /path/to/license.txt)"
```
--------------------------------
### Example of Invalid Settings Configuration Error
Source: https://learn.emailengine.app/docs/configuration/prepared-settings
Illustrates the error message format when EmailEngine fails to start due to invalid settings. This helps in diagnosing configuration issues.
```text
Error: Invalid settings configuration
- webhooks: must be a valid URL
- webhookEvents: must be an array
```
--------------------------------
### Get Template Details API Response
Source: https://learn.emailengine.app/docs/sending/templates
Example JSON response for retrieving a single template's details, including its content (subject, text, HTML) and metadata.
```json
{
"account": "example",
"id": "AAABgUIbuG0AAAAE",
"name": "Welcome Email",
"description": "Welcome new users to the platform",
"format": "html",
"created": "2025-05-14T10:00:00.000Z",
"updated": "2025-05-14T12:00:00.000Z",
"content": {
"subject": "Welcome to {{{params.companyName}}}!",
"text": "Hello {{params.firstName}}...",
"html": "Hello {{params.firstName}}
..."
}
}
```
--------------------------------
### Starting and Enabling EmailEngine Instances
Source: https://learn.emailengine.app/docs/deployment/systemd
Commands to start and enable multiple EmailEngine instances managed by systemd. Ensure the service file is named appropriately (e.g., emailengine@3001.service).
```bash
sudo systemctl start emailengine@3001
sudo systemctl start emailengine@3002
sudo systemctl enable emailengine@3001
sudo systemctl enable emailengine@3002
```
--------------------------------
### C# HttpClient Example
Source: https://learn.emailengine.app/docs/api/get-v-1-account-account-text-text
This C# code snippet demonstrates how to use HttpClient to make a GET request to retrieve message text. Ensure you replace '' with your actual JWT.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/account/:account/text/:text");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Start a Delivery Test
Source: https://learn.emailengine.app/docs/advanced/email-authentication-testing
Initiate a test for any connected email account to verify its authentication setup. This endpoint creates a temporary mailbox, sends a test email, and analyzes its authentication headers.
```APIDOC
## Start a Delivery Test
### Description
Initiates an email authentication test for a specified account.
### Method
POST
### Endpoint
`/v1/delivery-test/account/{accountId}`
### Parameters
#### Path Parameters
- **accountId** (string) - Required - The ID of the account to test.
#### Request Body
- **{}** (object) - An empty JSON object.
### Request Example (cURL)
```bash
curl -X POST "http://localhost:3000/v1/delivery-test/account/my-account" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
```
### Request Example (Node.js)
```javascript
const response = await fetch(
'http://localhost:3000/v1/delivery-test/account/my-account',
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
}
);
const result = await response.json();
console.log('Test ID:', result.deliveryTest);
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the test initiation was successful.
- **deliveryTest** (string) - The unique ID for the initiated delivery test.
```
--------------------------------
### API Request: Get Account Information
Source: https://learn.emailengine.app/docs/deployment/security
Example of how to correctly retrieve account information using the account ID. Ensure you use the account ID, not the email address, for API requests.
```curl
# CORRECT: Use account ID
curl https://emailengine.example.com/v1/account/account_1234 \
-H "Authorization: Bearer TOKEN"
# INCORRECT: Cannot use email address
# curl https://emailengine.example.com/v1/account/user@example.com
# Account ID might be same as email, but usually is different
# Always use the account ID returned during account creation
```
--------------------------------
### Start EmailEngine Free Trial
Source: https://learn.emailengine.app/docs/licensing
Run EmailEngine without a license key to automatically start a 14-day free trial. This is useful for evaluation and testing.
```bash
# Simply start EmailEngine without license key
emailengine
```
--------------------------------
### C# HttpClient Example for Listing Gateways
Source: https://learn.emailengine.app/docs/api/get-v-1-gateways
This C# code snippet shows how to use HttpClient to make a GET request to the /v1/gateways endpoint. It demonstrates setting the Accept and Authorization headers.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/gateways");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Fetch Secrets from AWS Secrets Manager
Source: https://learn.emailengine.app/docs/deployment/security
Example script to fetch secrets from AWS Secrets Manager and store them in a .env file for EmailEngine. Ensure AWS CLI and jq are installed and configured.
```bash
#!/bin/bash
# fetch-secrets.sh - Example using AWS Secrets Manager
# Fetch secrets from AWS
aws secretsmanager get-secret-value \
--secret-id emailengine/production \
--query SecretString \
--output text > /tmp/secrets.json
# Write to .env file (EmailEngine loads .env from current directory)
echo "EENGINE_SECRET=$(jq -r .secret /tmp/secrets.json)" > .env
echo "EENGINE_REDIS=$(jq -r .redis /tmp/secrets.json)" >> .env
# Clean up
rm /tmp/secrets.json
# Start EmailEngine (will load .env automatically)
/usr/local/bin/emailengine
```
--------------------------------
### Pre-configure Webhooks at Startup
Source: https://learn.emailengine.app/docs/reference/configuration-options
Configure webhook settings, including URL, enabled status, and events, using the EENGINE_SETTINGS environment variable at startup. The '*' event type subscribes to all events.
```bash
EENGINE_SETTINGS='{"webhooks":"https://your-app.com/webhooks","webhooksEnabled":true,"webhookEvents":["*"]}'
```
--------------------------------
### C# HttpClient for OAuth 2.0 Request
Source: https://learn.emailengine.app/docs/api/get-v-1-oauth-2
Example of using C# HttpClient to make a GET request to the OAuth 2.0 endpoint. Ensure the Authorization header is correctly formatted with your Bearer token.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/oauth2");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### Get Template Response Example
Source: https://learn.emailengine.app/docs/api/get-v-1-templates-template-template
This JSON object represents a successful response when retrieving template information. It includes details about the account, template ID, name, description, creation/update timestamps, and content.
```json
{
"account": "user123",
"id": "AAABgS-UcAYAAAABAA",
"name": "Transaction receipt",
"description": "Something about the template",
"format": "html",
"created": "2021-02-17T13:43:18.860Z",
"updated": "2021-02-17T13:43:18.860Z",
"content": {
"subject": "What a wonderful message",
"text": "Hello from myself!",
"html": "Hello from myself!
",
"previewText": "Welcome to our newsletter!",
"format": "html"
}
}
```
--------------------------------
### Install EmailEngine with Docker
Source: https://learn.emailengine.app/docs/email-api
Quickly set up EmailEngine using Docker. Ensure to configure the Redis connection string.
```bash
# Docker (quickest)
docker run -p 3000:3000 \
--env EENGINE_REDIS="redis://host.docker.internal:6379/8" \
postalsys/emailengine:v2
```
--------------------------------
### Create Account C# Example
Source: https://learn.emailengine.app/docs/api/post-v-1-account
Example of how to create a new email account using HttpClient in C#. Ensure you replace placeholders like with your actual credentials and server details.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://emailengine.example.com/v1/account");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var content = new StringContent("{\n \"account\": \"example\",\n \"name\": \"Nyan Cat\",\n \"email\": \"nyan.cat@example.com\",\n \"imap\": {\n \"auth\": {\n \"user\": \"nyan.cat\",\n \"pass\": \"sercretpass\"\n },\n \"host\": \"mail.example.com\",\n \"port\": 993,\n \"secure\": true\n },\n \"smtp\": {\n \"auth\": {\n \"user\": \"nyan.cat\",\n \"pass\": \"secretpass\"\n },\n \"host\": \"mail.example.com\",\n \"port\": 465,\n \"secure\": true\n }\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
--------------------------------
### C# HttpClient Example
Source: https://learn.emailengine.app/docs/api/get-v-1-outbox
This C# code snippet demonstrates how to make a GET request to the Outbox API using HttpClient. It includes setting the Authorization header with a Bearer token and handling the response.
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://emailengine.example.com/v1/outbox");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```