Email Channels¶
The Konigle SDK provides comprehensive email channel management for organizing different types of email flows within an account. Email channels separate transactional, marketing, and broadcast emails, each with their own configuration, quotas, and rate limiting.
Understanding Email Channels¶
Email channels are logical separations within an email account that allow you to:
- Organize emails by type (transactional, marketing, broadcast)
- Track performance and deliverability by channel type
Different channels have different quota and rate limits.
Creating Email Channels¶
Basic Channel Creation¶
import konigle
from konigle.models.comm import EmailChannelCreate, EmailChannelType
client = konigle.Client(api_key="your-api-key")
# Create a transactional email channel
channel_data = EmailChannelCreate(
code="order-confirmations",
channel_type=EmailChannelType.TRANSACTIONAL
)
channel = client.email_channels.create(channel_data)
print(f"Created channel: {channel.id}")
print(f"Channel code: {channel.code}")
print(f"Channel type: {channel.channel_type}")
print(f"Status: {channel.status}")
print(f"Daily quota: {channel.daily_quota}")
print(f"Rate limit: {channel.rate_limit} emails/second")
An account can have upto 5 channels.
Listing Email Channels¶
Basic Channel Listing¶
# List all channels with pagination
channels = client.email_channels.list(page=1, page_size=20)
print(f"Total channels: {channels.count}")
print(f"Current page: {channels.current_page}")
print(f"Total pages: {channels.num_pages}")
for channel in channels.payload:
print(f"- {channel.code} ({channel.channel_type})")
print(f" Status: {channel.status}")
print(f" Daily quota: {channel.daily_quota}")
print(f" Rate limit: {channel.rate_limit}/sec")
print(f" Created: {channel.created_at}")
Filtering Channels¶
from konigle.filters.comm import EmailChannelFilters
# Using filter object (type-safe)
channel_filters = EmailChannelFilters(
q="order", # Search in code and type
channel_type="transactional",
status="active",
)
filtered_channels = client.email_channels.list(
page=1,
page_size=10,
filters=channel_filters
)
# Using filter kwargs (more concise)
marketing_channels = client.email_channels.list(
channel_type="marketing",
ordering="-created_at" # Sort by newest first
)
# Get only active channels
active_channels = client.email_channels.list(status="active")
# Search channels by text
search_results = client.email_channels.list(q="newsletter")
Getting a Specific Channel¶
# Get channel by ID
channel = client.email_channels.get("channel_123456789")
print(f"Channel: {channel.code}")
print(f"Type: {channel.channel_type}")
print(f"Status: {channel.status}")
print(f"Account: {channel.account}")
print(f"Daily quota: {channel.daily_quota}")
print(f"Rate limit: {channel.rate_limit}")
if channel.suspension_reason:
print(f"Suspension reason: {channel.suspension_reason}")
if channel.suspended_at:
print(f"Suspended at: {channel.suspended_at}")
Updating Email Channels¶
from konigle.models.comm import EmailChannelUpdate
# Update channel code
update_data = EmailChannelUpdate(
code="updated-channel-code"
)
updated_channel = client.email_channels.update("channel_123456789", update_data)
print(f"Updated channel code: {updated_channel.code}")
# Note: Channel type cannot be updated after creation
# You need to create a new channel if you need a different type
Engagement Tracking¶
Email channels support engagement tracking, which allows you to track open and click events for emails sent through the channel. When enabled, the system automatically adds tracking pixels and rewrites links in emails.
When enabled, the open and click events are tracked for the campaign emails.
Deliverability Impact
Engagement tracking is disabled by default because it could reduce email deliverability and cause emails to end up in spam. Enable this feature only if you understand the trade-offs.
Enable Engagement Tracking¶
# Enable engagement tracking for a channel
channel = client.email_channels.set_engagement_tracking(
"channel_123456789",
enable=True
)
print(f"Engagement tracking enabled: {channel.enable_engagement_tracking}")
Disable Engagement Tracking¶
# Disable engagement tracking for a channel
channel = client.email_channels.set_engagement_tracking(
"channel_123456789",
enable=False
)
print(f"Engagement tracking disabled: {channel.enable_engagement_tracking}")
Async Engagement Tracking¶
import asyncio
import konigle
async def manage_engagement_tracking():
async with konigle.AsyncClient(api_key="your-api-key") as client:
# Enable engagement tracking
channel = await client.email_channels.set_engagement_tracking(
"channel_123456789",
enable=True
)
print(f"Tracking enabled: {channel.enable_engagement_tracking}")
# Disable engagement tracking
channel = await client.email_channels.set_engagement_tracking(
"channel_123456789",
enable=False
)
print(f"Tracking disabled: {channel.enable_engagement_tracking}")
asyncio.run(manage_engagement_tracking())
Deleting Email Channels¶
# Delete an email channel
success = client.email_channels.delete("channel_123456789")
if success:
print("Channel deleted successfully")
else:
print("Failed to delete channel")
Async Operations¶
import asyncio
import konigle
async def manage_email_channels():
async with konigle.AsyncClient(api_key="your-api-key") as client:
# Create channel
channel_data = EmailChannelCreate(
code="async-channel",
channel_type=EmailChannelType.TRANSACTIONAL
)
channel = await client.email_channels.create(channel_data)
# List channels with filtering
channels = await client.email_channels.list(
page_size=10,
channel_type="transactional"
)
# Update channel
update_data = EmailChannelUpdate(code="updated-async-channel")
updated_channel = await client.email_channels.update(channel.id, update_data)
# Delete channel
await client.email_channels.delete(channel.id)
asyncio.run(manage_email_channels())
CLI Commands¶
The Konigle CLI provides comprehensive email channel management commands.
Channel Creation¶
# Create a transactional email channel
konigle comm email channels create \
--code "order-confirmations" \
--type transactional
# Create a marketing email channel
konigle comm email channels create \
--code "newsletter-campaign" \
--type marketing
# Create a broadcast email channel
konigle comm email channels create \
--code "system-announcements" \
--type broadcast
Channel Listing¶
# List all channels
konigle comm email channels list
# List with pagination
konigle comm email channels list --page 2 --page-size 5
# List with search
konigle comm email channels list --search "newsletter"
# List by channel type
konigle comm email channels list --type transactional
# List by status
konigle comm email channels list --status active
# Combine filters
konigle comm email channels list \
--type marketing \
--status active \
--search "campaign"
Channel Details¶
Channel Updates¶
# Update channel code
konigle comm email channels update channel_123456789 \
--code "new-channel-code"
Engagement Tracking¶
# Enable engagement tracking for a channel
konigle comm email channels set-engagement-tracking channel_123456789 \
--enable
# Disable engagement tracking for a channel
konigle comm email channels set-engagement-tracking channel_123456789 \
--disable
# Enable is the default if no flag is provided
konigle comm email channels set-engagement-tracking channel_123456789