import Migma from 'migma';const migma = new Migma(process.env.MIGMA_API_KEY);// A project holds your brand info (colors, fonts, logos, tone of voice).// Import one from your website, or use an existing project ID from the dashboard.const brand = await migma.projects.importAndWait({ urls: ['https://yourbrand.com']});// Generate an email design with AI — returns the finished HTML directlyconst email = await migma.emails.generateAndWait({ projectId: brand.data.projectId, prompt: 'Create a welcome email for new subscribers', languages: ['en']});if (email.data?.status === 'completed') { console.log('Subject:', email.data.result.subject); console.log('HTML:', email.data.result.html); // production-ready email HTML}
Prefer async? Use migma.emails.generate() to kick off generation without waiting, then set up a webhook to receive an email.generation.completed event when the design is ready — no polling needed.
OpenClaw (formerly ClawdBot) is an open-source AI agent for WhatsApp, Telegram, and Discord. Pair it with Migma to generate and send professional emails from a single chat command.
import Migma from 'migma';const migma = new Migma(process.env.MIGMA_API_KEY);// 1. Set up an instant sending domain (no DNS needed — see /sending-domains/overview)await migma.domains.createManaged({ prefix: 'yourcompany' });// 2. Generate an on-brand email with AIconst { data: email } = await migma.emails.generateAndWait({ projectId: process.env.MIGMA_PROJECT_ID, // your brand project prompt: 'Create a summer sale email with 30% off everything',});// 3. Send it — conversationId resolves template and project automaticallyawait migma.sending.send({ recipientType: 'email', recipientEmail: 'sarah@example.com', from: 'hello@yourcompany.migma.email', fromName: 'Your Company', subject: email.data.result.subject, conversationId: email.data.conversationId,});
Full OpenClaw Tutorial
Step-by-step guide: API key, sending domain, project setup, and sending from WhatsApp/Telegram/Discord.
Email generation, brand import, and preview creation are asynchronous. The SDK provides *AndWait helpers that poll automatically until the operation completes:
const email = await migma.emails.generateAndWait( { projectId: 'proj_123', prompt: 'Create a product launch email' }, { interval: 2000, // poll every 2s (default) maxAttempts: 150, // give up after 150 polls (default) onPoll: (status, attempt) => { console.log(`Poll ${attempt}: ${status.status}`); } });
All three polling methods:
Method
Waits for
migma.emails.generateAndWait()
Email generation to complete
migma.projects.importAndWait()
Brand import to finish
migma.previews.createAndWait()
Device preview screenshots
You can cancel any polling operation with an AbortController:
const controller = new AbortController();setTimeout(() => controller.abort(), 60000); // 60s timeoutconst result = await migma.emails.generateAndWait(params, { signal: controller.signal});
Here’s a full workflow — import a brand, generate an email, export it, and send:
import Migma from 'migma';const migma = new Migma(process.env.MIGMA_API_KEY);// 1. Import your brandconst brand = await migma.projects.importAndWait({ urls: ['https://yourbrand.com']});console.log('Brand imported:', brand.data.projectId);// 2. Generate an email with AIconst email = await migma.emails.generateAndWait({ projectId: brand.data.projectId, prompt: 'Create a password reset email', languages: ['en']});console.log('Email ready:', email.data.conversationId);// 3. Send it — conversationId resolves template and project automaticallyawait migma.sending.send({ recipientType: 'email', recipientEmail: 'sarah@example.com', from: 'hello@yourbrand.migma.email', fromName: 'Your Brand', subject: 'Reset your password', conversationId: email.data.conversationId,});
By default, emails send through Migma’s built-in infrastructure. You can also send via Amazon SES, Resend, SendGrid, or Mailgun by connecting your provider and passing providerType in the send call.