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}`);
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);
Show SmtpConfig properties
Whether TLS/SSL is enabled
updateSmtpConfig()
Updates the SMTP server configuration.
await workspace.emails.updateSmtpConfig({
port: 2525,
host: 'localhost',
secure: false,
});
data
Partial<SmtpConfig>
required
Show SmtpConfig properties
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}`);
}
Show ListEmailOptions properties
Number of emails per page
return
Promise<PaginatedResult<EmailData>>
Show PaginatedResult properties
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 of the email to retrieve
Show EmailData properties
Recipient email address(es)
HTML version of the email body
Timestamp when email was received
deleteEmail()
Deletes an email from the test inbox.
await workspace.emails.deleteEmail('email-id');
ID of the email to delete
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