Skip to content

Email Accounts

The Konigle SDK provides comprehensive email account management for handling email configuration, serving as the main container for email channels and identities. Email accounts contain default settings and serve as the parent for all email-related resources.

Creating Email Accounts

Basic Account Creation

import konigle
from konigle.models.comm import EmailAccountCreate

client = konigle.Client(api_key="your-api-key")

# Create a basic email account
account_data = EmailAccountCreate(
    name="Marketing Account",
    default_from_email="noreply@example.com",
    default_from_name="Example Team",
    default_reply_to_email="support@example.com",
    default_reply_to_name="Support Team"
)

account = client.email_accounts.create(account_data)
print(f"Created account: {account.id}")
print(f"Account name: {account.name}")
print(f"Active: {account.is_active}")

Complete Account Setup

The setup method creates an account with default channels and identity in one operation:

from konigle.models.comm import EmailAccountSetup

# Setup account with all components at once
setup_data = EmailAccountSetup(
    account_name="Company Email Account",
    default_from_email="noreply@company.com",
    default_reply_to_email="support@company.com",
    identity_value="company.com"  # Domain to verify
)

result = client.email_accounts.setup(setup_data)

# Get the created resources
account = result["account"]
channels = result["channels"]  # List of default channels
identity = result["identity"]   # Created identity

print(f"✓ Account created: {account.name}")
print(f"✓ Channels created: {len(channels)}")
print(f"✓ Identity created: {identity.identity_value}")
print(f"✓ Identity verified: {identity.verified}")

# Display DKIM records if available for verification
if identity.dkim_records:
    print("\n🔧 DKIM Records Required:")
    for i, record in enumerate(identity.dkim_records, 1):
        print(f"Record {i}:")
        print(f"  Type: {record['type']}")
        print(f"  Name: {record['name']}")
        print(f"  Value: {record['value']}")

Listing Email Accounts

Basic Account Listing

# List all accounts with pagination
accounts = client.email_accounts.list(page=1, page_size=20)

print(f"Total accounts: {accounts.count}")
print(f"Current page: {accounts.current_page}")
print(f"Total pages: {accounts.num_pages}")

for account in accounts.payload:
    print(f"- {account.name} (ID: {account.id})")
    print(f"  Active: {account.is_active}")
    print(f"  From Email: {account.default_from_email}")
    print(f"  Created: {account.created_at}")

A website can only have one email account. So this will just return a single account if it exists.

Getting a Specific Account

# Get account by ID
account = client.email_accounts.get("account_123456789")
print(f"Account: {account.name}")
print(f"From Email: {account.default_from_email}")
print(f"From Name: {account.default_from_name}")
print(f"Reply-To Email: {account.default_reply_to_email}")
print(f"Reply-To Name: {account.default_reply_to_name}")
print(f"Active: {account.is_active}")
print(f"Created: {account.created_at}")

Updating Email Accounts

from konigle.models.comm import EmailAccountUpdate

# Update account information
update_data = EmailAccountUpdate(
    name="Updated Marketing Account",
    default_from_email="marketing@example.com",
    default_from_name="Marketing Team",
    default_reply_to_email="noreply@example.com",
    default_reply_to_name="No Reply"
)

updated_account = client.email_accounts.update("account_123456789", update_data)
print(f"Updated account: {updated_account.name}")

# Update specific fields only
partial_update = EmailAccountUpdate(
    name="New Account Name"
)
account = client.email_accounts.update("account_123456789", partial_update)

# Clear optional fields by setting empty string
clear_reply_to = EmailAccountUpdate(
    default_reply_to_email="",
    default_reply_to_name=""
)
account = client.email_accounts.update("account_123456789", clear_reply_to)

Deleting Email Accounts

# Delete an email account
success = client.email_accounts.delete("account_123456789")
if success:
    print("Account deleted successfully")
else:
    print("Failed to delete account")

# Note: Deleting an account will also delete associated channels and identities

Async Operations

import asyncio
import konigle

async def manage_email_accounts():
    async with konigle.AsyncClient(api_key="your-api-key") as client:
        # Setup account with all components
        setup_data = EmailAccountSetup(
            account_name="Async Account",
            default_from_email="async@example.com",
            identity_value="example.com"
        )
        result = await client.email_accounts.setup(setup_data)
        account = result["account"]

        # List accounts with filtering
        accounts = await client.email_accounts.list(
            page_size=10,
            q="async"
        )

        # Update account
        update_data = EmailAccountUpdate(name="Updated Async Account")
        updated_account = await client.email_accounts.update(account.id, update_data)

        # Delete account
        await client.email_accounts.delete(account.id)

asyncio.run(manage_email_accounts())

CLI Commands

The Konigle CLI provides comprehensive email account management commands.

Account Setup

# Setup complete email account with default channel and identity
konigle comm email accounts setup \
    --name "Marketing Account" \
    --from-email "marketing@company.com" \
    --reply-to-email "noreply@company.com" \
    --identity-value "company.com"

Account Creation

# Create a basic email account
konigle comm email accounts create \
    --name "Support Account" \
    --from-email "support@company.com" \
    --from-name "Support Team" \
    --reply-to-email "noreply@company.com" \
    --reply-to-name "No Reply"

# Create minimal account
konigle comm email accounts create --name "Basic Account"

Account Listing

# List all accounts
konigle comm email accounts list

# List with pagination
konigle comm email accounts list --page 2 --page-size 5

# List with custom page size
konigle comm email accounts list --page-size 20

Account Details

# Get specific account details
konigle comm email accounts get account_123456789

Account Updates

# Update account name
konigle comm email accounts update account_123456789 --name "New Account Name"

# Update email settings
konigle comm email accounts update account_123456789 \
    --from-email "new@company.com" \
    --from-name "New Team" \
    --reply-to-email "support@company.com"

# Update multiple fields
konigle comm email accounts update account_123456789 \
    --name "Updated Account" \
    --from-email "updated@company.com" \
    --reply-to-email "support@company.com"

Account Deletion

# Delete account with confirmation
konigle comm email accounts delete account_123456789

# Delete account without confirmation
konigle comm email accounts delete account_123456789 --yes