Misar Docs
MisarMailMisar.BlogMisarReachMisarPostMisar.DevMisar PlatformMisar IdentityMisar Posts API
Sdks

Swift SDK

Install and use the MisarMail Swift SDK

Installation

Add to Package.swift:

dependencies: [
    .package(url: "https://github.com/misarai/misarmail-swift.git", from: "1.0.0"),
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "MisarMail", package: "misarmail-swift"),
    ]),
]

Quick Start

import MisarMail

let client = MisarMailClient(apiKey: ProcessInfo.processInfo.environment["MISARMAIL_API_KEY"]!)

let request = SendRequest(
    from: Address(email: "[email protected]", name: "Misar"),
    to: [Address(email: "[email protected]")],
    subject: "Welcome",
    html: "<p>Hello from MisarMail!</p>"
)

let result = try await client.send(request)
print("Sent: \(result.messageId)")

Available Methods

MethodDescription
client.send(_ request:)Send a transactional email
client.contacts.list(params:)List contacts
client.contacts.create(_ request:)Create a contact
client.contacts.get(_ id:)Get a contact
client.contacts.update(_ id:, _ request:)Update a contact
client.contacts.delete(_ id:)Delete a contact
client.contacts.importContacts(_ request:)Bulk import contacts
client.campaigns.list(params:)List campaigns
client.campaigns.create(_ request:)Create a campaign
client.campaigns.get(_ id:)Get a campaign
client.campaigns.update(_ id:, _ request:)Update a campaign
client.campaigns.send(_ id:)Send/schedule a campaign
client.campaigns.delete(_ id:)Delete a campaign
client.templates.list(params:)List templates
client.templates.create(_ request:)Create a template
client.templates.get(_ id:)Get a template
client.templates.update(_ id:, _ request:)Update a template
client.templates.delete(_ id:)Delete a template
client.templates.render(_ id:, _ request:)Render a template with merge data
client.automations.list(params:)List automations
client.automations.create(_ request:)Create an automation
client.automations.get(_ id:)Get an automation
client.automations.update(_ id:, _ request:)Update an automation
client.automations.delete(_ id:)Delete an automation
client.automations.activate(_ id:)Activate/deactivate an automation
client.domains.list()List sending domains
client.domains.create(_ request:)Add a sending domain
client.domains.get(_ id:)Get a domain
client.domains.verify(_ id:)Trigger domain DNS verification
client.domains.delete(_ id:)Delete a domain
client.aliases.list(params:)List email aliases
client.aliases.create(_ request:)Create an alias
client.aliases.get(_ id:)Get an alias
client.aliases.update(_ id:, _ request:)Update an alias
client.aliases.delete(_ id:)Delete an alias
client.dedicatedIPs.list()List dedicated IPs
client.dedicatedIPs.create(_ request:)Purchase a dedicated IP
client.dedicatedIPs.update(_ id:, _ request:)Update IP pool assignment
client.dedicatedIPs.delete(_ id:)Release a dedicated IP
client.abTests.list(params:)List A/B tests
client.abTests.create(_ request:)Create an A/B test
client.abTests.get(_ id:)Get an A/B test
client.abTests.setWinner(_ id:, variant:)Manually set the winning variant
client.sandbox.send(_ request:)Send in sandbox mode
client.sandbox.list(params:)List sandbox messages
client.sandbox.delete(_ id:)Delete a sandbox message
client.inbound.list(params:)List inbound routing rules
client.inbound.create(_ request:)Create an inbound route
client.inbound.get(_ id:)Get an inbound route
client.inbound.delete(_ id:)Delete an inbound route
client.analytics.overview(params:)Get send/open/click/bounce analytics
client.track.event(_ request:)Track a custom event
client.track.purchase(_ request:)Track a purchase event
client.keys.list()List API keys
client.keys.create(_ request:)Create an API key
client.keys.get(_ id:)Get an API key
client.keys.revoke(_ id:)Revoke an API key
client.validate.email(_ address:)Validate an email address
client.webhooks.list(params:)List webhooks
client.webhooks.create(_ request:)Create a webhook endpoint
client.webhooks.get(_ id:)Get a webhook
client.webhooks.update(_ id:, _ request:)Update a webhook
client.webhooks.delete(_ id:)Delete a webhook
client.webhooks.test(_ id:)Send a test event to a webhook
client.usage.get(params:)Get API usage stats
client.billing.subscription()Get current subscription details
client.billing.checkout(_ request:)Create a billing checkout session
client.workspaces.list()List workspaces
client.workspaces.create(_ request:)Create a workspace
client.workspaces.get(_ id:)Get a workspace
client.workspaces.update(_ id:, _ request:)Update a workspace
client.workspaces.delete(_ id:)Delete a workspace
client.workspaces.listMembers(_ id:)List workspace members
client.workspaces.inviteMember(_ id:, _ request:)Invite a member to workspace
client.workspaces.updateMember(_ id:, userId:, _ request:)Update member role
client.workspaces.removeMember(_ id:, userId:)Remove a member from workspace

Examples

Webhooks

let webhook = try await client.webhooks.create(CreateWebhookRequest(
    url: "https://yourapp.com/webhooks/mail",
    events: ["email.delivered", "email.opened", "email.bounced"]
))
try await client.webhooks.test(webhook.id)

Error Handling

do {
    let result = try await client.send(request)
    print(result.messageId)
} catch let error as MisarMailError {
    print("\(error.statusCode): \(error.message)")
}