Skip to content

EmailOS Template Command Documentation ​

The mailos template command manages HTML email templates for styling outgoing emails with custom designs and branding.

Basic Usage ​

bash
mailos template

Opens interactive template management interface with options to create, edit, preview, or list templates.

Command-Line Flags ​

Basic Options ​

FlagShortTypeDefaultDescriptionExample
--accountstringEmail account to usemailos template --account value
--contentstringHTML content for templatemailos template --content value
--fromstringEmail account to use (alias for --account)mailos template --from value

Advanced Options ​

FlagShortTypeDefaultDescriptionExample
--copystringCopy from existing template namemailos template --copy value
--editboolfalseOpen template in default HTML editormailos template --edit
--filestringRead HTML content from filemailos template --file value
--imagestringLocal image file to embed as base64mailos template --image value
--namestringTemplate namemailos template --name value
--open-browserboolfalseOpen template HTML file in browsermailos template --open-browser
--removeboolfalseRemove existing templatemailos template --remove
--template-dirstringSet template directory for accountmailos template --template-dir value

Interactive Template Management ​

Running mailos template without flags opens an interactive menu with three options:

1. Create/Edit Template ​

  • Prompts for template name if not provided with --name
  • Multi-line HTML input terminated by typing "END" on a new line
  • Validates that template contains placeholder
  • Optional preview before saving
  • Saves to appropriate location (local or global)

2. Preview Existing Template ​

  • Lists available templates if no name specified
  • Loads template and opens preview in browser with sample content
  • Replaces placeholders with preview data for visual testing

3. List Templates ​

  • Shows all available templates from both local and global locations
  • Displays template names and their file paths

Template System ​

Placeholder Variables ​

Templates support the following placeholders that are replaced when emails are sent:

  • - Email content (required)
  • - Profile picture (optional)

Storage Locations ​

Templates are stored with priority order:

  1. Local project: .email/templates/[name].html
  2. Global user: ~/.email/templates/[name].html

Local templates take precedence over global ones with the same name.

Template Files ​

  • Saved as HTML files with .html extension
  • Named templates: [name].html
  • Default template: default.html

Quick Actions ​

View Template in Browser ​

bash
mailos template --open-browser

Opens your current default template HTML file directly in the browser for visual inspection. Useful for:

  • Quick visual review of template design
  • Testing template appearance without sending emails
  • Debugging layout issues

Create Named Template ​

bash
mailos template --name company

Creates or edits a template with the specified name.

Remove Template ​

bash
mailos template --remove --name company

Removes the specified template. If no name provided, removes "default" template.

Template Structure ​

Basic Template Example ​

html
<html>
  <body style="font-family: Arial; padding: 20px;">
    <div class="header">
      {{PROFILE_IMAGE}}
      <h1>My Company</h1>
    </div>
    <div class="content">
      {{BODY}}
    </div>
    <div class="footer">
      <p>© 2024 My Company</p>
    </div>
  </body>
</html>

Professional Template Example ​

html
<!DOCTYPE html>
<html>
<head>
  <style>
    .email-container {
      max-width: 600px;
      margin: 0 auto;
      font-family: Arial, sans-serif;
      color: #333;
    }
    .header {
      background: #2c3e50;
      color: white;
      padding: 20px;
      text-align: center;
    }
    .content {
      padding: 30px;
      background: #ffffff;
    }
    .footer {
      background: #ecf0f1;
      padding: 20px;
      text-align: center;
      font-size: 12px;
    }
  </style>
</head>
<body>
  <div class="email-container">
    <div class="header">
      <h1>Professional Email</h1>
    </div>
    <div class="content">
      {{BODY}}
    </div>
    <div class="footer">
      Contact information and unsubscribe links
    </div>
  </div>
</body>
</html>

Minimal Template Example ​

html
<div style="max-width: 500px; margin: 20px auto; font-family: Georgia, serif;">
  <div style="border-bottom: 2px solid #e0e0e0; padding-bottom: 10px; margin-bottom: 20px;">
    {{PROFILE_IMAGE}}
    <span style="margin-left: 10px; font-size: 18px;">Company Name</span>
  </div>
  <div style="line-height: 1.6;">
    {{BODY}}
  </div>
  <div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #e0e0e0; font-size: 14px; color: #666;">
    Best regards,<br>
    Your Name
  </div>
</div>

Profile Images ​

Profile Image Handling ​

When placeholder is used:

  • Images are base64-encoded and embedded directly in the email
  • Supported formats: JPG, JPEG, PNG, GIF, WEBP
  • Automatically styled with max-width: 150px; border-radius: 50%;
  • If no profile image is configured, placeholder is removed

Profile Image Tag Output ​

The system generates HTML like:

html
<img src="data:image/jpeg;base64,[encoded-data]" alt="Profile" style="max-width: 150px; height: auto; border-radius: 50%;">

Integration with Email System ​

Automatic Template Application ​

Templates are automatically applied when:

  • Sending emails with mailos send command
  • Email body contains markdown or HTML content
  • Template file exists for the specified name (default: "default")

Template Bypass ​

Templates are bypassed when:

  • Using --plain flag with send commands
  • No template file exists
  • Template loading fails

Template Management Commands ​

List All Templates ​

bash
mailos template
# Choose option 3: List templates

Shows all available templates with their file paths.

Preview Template ​

bash
mailos template
# Choose option 2: Preview existing template

Opens template in browser with sample content for visual testing.

Edit Existing Template ​

bash
mailos template --name existing-template
# Choose option 1: Create/Edit template

Loads existing template for modification or creates new one if it doesn't exist.

Best Practices ​

Email Client Compatibility ​

  • Use inline CSS for maximum compatibility
  • Avoid JavaScript (not supported by most email clients)
  • Test with multiple email clients (Gmail, Outlook, Apple Mail)
  • Use table layouts for complex designs if needed

Performance and Size ​

  • Keep total email size under 100KB
  • Optimize images before base64 encoding
  • Minimize CSS to reduce file size
  • Avoid external dependencies

Accessibility ​

  • Include alt text for images
  • Use semantic HTML structure
  • Ensure sufficient color contrast
  • Test with screen readers

Mobile Optimization ​

  • Use responsive design principles
  • Test on mobile devices
  • Ensure readable font sizes
  • Make tap targets large enough

Troubleshooting ​

Template Not Applied ​

  • Verify template file exists at expected location
  • Check that template contains placeholder
  • Ensure not using --plain flag when sending
  • Validate HTML syntax

Images Not Showing ​

  • Check that profile image file exists and is readable
  • Verify image format is supported (JPG, PNG, GIF, WEBP)
  • Ensure image file size is reasonable (under 1MB recommended)

Browser Preview Issues ​

  • Check that default browser is configured
  • Verify template file permissions
  • Test opening file manually in browser

Template Saving Issues ​

  • Ensure directory permissions allow file creation
  • Check available disk space
  • Verify file path is valid and accessible

Examples ​

Creating Company Template ​

bash
mailos template --name company
# Paste your company HTML template
# Type "END" when finished
# Preview if desired
# Confirm save

Quick Browser Preview ​

bash
mailos template --open-browser

Remove Old Template ​

bash
mailos template --remove --name old-template

List Available Templates ​

bash
mailos template
# Choose option 3

File Locations ​

Templates are stored in these locations based on your configuration:

  • Local Project: .email/templates/[name].html (if .email directory exists)
  • Global User: ~/.email/templates/[name].html (default location)

The system automatically creates the necessary directories when saving templates.

Released under the MIT License.