Sending Emails via SMTP

Send emails through Cakemail's SMTP gateway using standard SMTP protocol. This allows you to leverage the full power of Cakemail's Email API without modifying your existing SMTP-based applications.

Overview

The SMTP gateway provides a familiar interface for developers already using SMTP. Simply configure your SMTP client to use Cakemail's server with your account credentials.

Benefits:

  • Use existing SMTP libraries and code
  • Minimal changes to legacy applications
  • Standard protocol with wide language support
  • Industry-leading deliverability

Email API Subscription Required

Before using SMTP, you need an active Email API account with a valid subscription.

Learn more at cakemail.com/solutions/email-api.

SMTP Configuration

SettingValue
Hostsmtp.cakemail.dev
Port465
EncryptionSSL/TLS (SMTPS)
AuthenticationYour Cakemail username and password

Prerequisites

Sender Requirements

Your sender address must be:

  • Registered in your Cakemail account
  • Validated through email verification
  • Authenticated with SPF/DKIM records
  • Tracking domain branded on your domain

The From: header must match a validated sender. Emails from unvalidated senders will be rejected.

List ID

Contact management is required for compliance and bounce handling. You'll need a List ID from your Cakemail account. Find your default list or create a new one through the Lists API.

Required Headers

x-email-api-enabled

Format: x-email-api-enabled: true

Enables Email API routing for this message. Required for all SMTP messages.

x-list-id

Format: x-list-id: <list-id>

Associates the email with a Cakemail list. Required by default.

Why x-list-id is required:

  • Consent management: Maintains compliance with email regulations
  • Bounce handling: Automatically processes bounces and unsubscribes
  • Contact management: Recipients not in the list are automatically added

If your use case justifies not using a list ID, contact support@cakemail.com.

Optional Headers

HeaderFormatDefaultPurpose
x-email-api-typemarketing or transactionalmarketingEmail type classification
x-tagstag1,tag2NoneComma-separated tags for filtering

Quick Start

curl -v \
    --mail-from 'sender@example.com' \
    --mail-rcpt 'recipient@example.com' \
    smtps://smtp.cakemail.dev:465 \
    --user "your-username:your-password" \
    --upload-file - <<EOF
From: sender@example.com
To: recipient@example.com
Subject: Test Email
x-email-api-enabled: true
x-list-id: 9234980

This is the email body content.
EOF

Code Examples

Python (smtplib)

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

smtp_server = "smtp.cakemail.dev"
smtp_port = 465
username = "your-username"
password = "your-password"

msg = MIMEMultipart()
msg['From'] = 'sender@example.com'
msg['To'] = 'recipient@example.com'
msg['Subject'] = 'Test Email'
msg['x-email-api-enabled'] = 'true'
msg['x-list-id'] = '9234980'

body = "This is the email body content."
msg.attach(MIMEText(body, 'plain'))

with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:
    server.login(username, password)
    server.send_message(msg)
    print("Email sent successfully!")

Node.js (nodemailer)

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: 'smtp.cakemail.dev',
  port: 465,
  secure: true,
  auth: {
    user: 'your-username',
    pass: 'your-password'
  }
});

const mailOptions = {
  from: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Test Email',
  text: 'This is the email body content.',
  headers: {
    'x-email-api-enabled': 'true',
    'x-list-id': '9234980'
  }
};

transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    console.error('Error:', error);
  } else {
    console.log('Email sent:', info.response);
  }
});

PHP (PHPMailer)

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host       = 'smtp.cakemail.dev';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'your-username';
    $mail->Password   = 'your-password';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;

    $mail->setFrom('sender@example.com');
    $mail->addAddress('recipient@example.com');

    $mail->addCustomHeader('x-email-api-enabled', 'true');
    $mail->addCustomHeader('x-list-id', '9234980');

    $mail->Subject = 'Test Email';
    $mail->Body    = 'This is the email body content.';

    $mail->send();
    echo 'Email sent successfully!';
} catch (Exception $e) {
    echo "Email could not be sent. Error: {$mail->ErrorInfo}";
}

Troubleshooting

Authentication Failed

  • Verify your Cakemail username and password
  • Ensure your account has API access enabled

Connection Refused

  • Confirm you're using port 465 with SSL/TLS
  • Check if your firewall allows outbound connections on port 465
  • Verify the hostname is smtp.cakemail.dev

Email Not Delivered

  • Ensure x-email-api-enabled: true header is included
  • Confirm the sender email is validated and authenticated
  • Check that x-list-id contains a valid list ID
  • Review spam/junk folders

Limitations

  • Single recipient per SMTP call — send separately for multiple recipients
  • Attachments disabled by default — contact support@cakemail.com to enable