Skip to main content
The EmailModule provides methods to configure SMTP settings and view received emails during testing.

Access the module

Access the email module through a workspace instance:
const workspace = yasumu.workspaces.getActiveWorkspace();
const emailModule = workspace.emails;

// Get SMTP configuration
const config = await emailModule.getSmtpConfig();
console.log(`SMTP Port: ${config.port}`);

SMTP configuration

getSmtpPort()

Returns the currently configured SMTP port.
const port = await workspace.emails.getSmtpPort();
console.log(`SMTP listening on port ${port}`);
return
Promise<number | null>
The SMTP port number, or null if not configured

getSmtpConfig()

Retrieves the complete SMTP server configuration.
const config = await workspace.emails.getSmtpConfig();
console.log(config);
return
Promise<SmtpConfig>

updateSmtpConfig()

Updates the SMTP server configuration.
await workspace.emails.updateSmtpConfig({
  port: 2525,
  host: 'localhost',
  secure: false,
});
data
Partial<SmtpConfig>
required
return
Promise<void>
Resolves when the configuration is updated

Email management

listEmails()

Lists received emails with pagination.
const result = await workspace.emails.listEmails({
  page: 1,
  limit: 20,
});

console.log(`Total emails: ${result.total}`);
console.log(`Current page: ${result.page}`);

for (const email of result.data) {
  console.log(`From: ${email.from}`);
  console.log(`To: ${email.to}`);
  console.log(`Subject: ${email.subject}`);
}
options
ListEmailOptions
required
return
Promise<PaginatedResult<EmailData>>

getEmail()

Retrieves a specific email by ID.
const email = await workspace.emails.getEmail('email-id');

console.log(`From: ${email.from}`);
console.log(`Subject: ${email.subject}`);
console.log(`Body: ${email.body}`);
id
string
required
ID of the email to retrieve
return
Promise<EmailData>

deleteEmail()

Deletes an email from the test inbox.
await workspace.emails.deleteEmail('email-id');
id
string
required
ID of the email to delete
return
Promise<void>
Resolves when the email is deleted

Example usage

// Configure SMTP server
await workspace.emails.updateSmtpConfig({
  port: 2525,
  host: 'localhost',
  secure: false,
});

const port = await workspace.emails.getSmtpPort();
console.log(`SMTP server running on port ${port}`);

// List received emails
const emails = await workspace.emails.listEmails({
  page: 1,
  limit: 10,
});

console.log(`Received ${emails.total} emails`);

for (const email of emails.data) {
  console.log('\n--- Email ---');
  console.log(`ID: ${email.id}`);
  console.log(`From: ${email.from}`);
  console.log(`To: ${email.to}`);
  console.log(`Subject: ${email.subject}`);
  console.log(`Received: ${email.receivedAt}`);
  
  // Get full email details
  const fullEmail = await workspace.emails.getEmail(email.id);
  console.log(`Body: ${fullEmail.body}`);
  
  if (fullEmail.attachments?.length > 0) {
    console.log(`Attachments: ${fullEmail.attachments.length}`);
  }
}

// Delete old emails
for (const email of emails.data) {
  await workspace.emails.deleteEmail(email.id);
}

console.log('Cleaned up test emails');

Testing email flows

Use the email module to test email-sending functionality:
// 1. Configure SMTP settings
await workspace.emails.updateSmtpConfig({
  port: 2525,
  host: 'localhost',
});

// 2. Your application sends emails to localhost:2525
// (this is done outside the SDK)

// 3. Check if emails were received
const emails = await workspace.emails.listEmails({
  page: 1,
  limit: 100,
});

// 4. Verify email content
const welcomeEmail = emails.data.find(
  (e) => e.subject === 'Welcome to our service'
);

if (welcomeEmail) {
  const full = await workspace.emails.getEmail(welcomeEmail.id);
  console.log('Welcome email received!');
  console.log('HTML content:', full.html);
} else {
  console.error('Welcome email not found');
}

// 5. Clean up after tests
for (const email of emails.data) {
  await workspace.emails.deleteEmail(email.id);
}

Workspace

Workspace management

RestModule

REST API testing

Build docs developers (and LLMs) love