AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import {
HttpMethod,
AuthenticationType,
httpClient,
} from '@activepieces/pieces-common';
import { lobstermailCommon, inboxIdDropdownOptional } from '../common';
import { lobstermailAuth } from '../..';
export const emailSentTrigger = createTrigger({
auth: lobstermailAuth,
name: 'email_sent',
classification: 'READ',
displayName: 'Email Sent',
description:
'Triggers when an outbound email is successfully delivered. Use for audit logs, CRM updates, or confirming delivery.',
aiMetadata: {
description: 'Fires via webhook when an outbound email is successfully delivered, optionally scoped to a single inbox. Each event represents one confirmed delivery with the message id, recipients, subject, and thread id. Use for delivery confirmation, audit logging, or downstream CRM updates.',
},
type: TriggerStrategy.WEBHOOK,
props: {
inbox_id: inboxIdDropdownOptional,
},
sampleData: {
event: 'email.sent',
email_id: 'eml_sample123',
inbox_id: 'ibx_sample456',
from: '[email protected]',
to: '[email protected]',
subject: 'Your order confirmation',
thread_id: null,
sent_at: '2026-01-01T00:00:00.000Z',
},
async onEnable(context) {
const body: Record<string, unknown> = {
url: context.webhookUrl,
events: ['email.sent'],
};
if (context.propsValue.inbox_id) {
body['inboxId'] = context.propsValue.inbox_id;
}
const response = await httpClient.sendRequest<{ id: string }>({
method: HttpMethod.POST,
url: `${lobstermailCommon.baseUrl}/v1/webhooks`,
body,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: context.auth.secret_text,
},
});
await context.store.put('webhookId', response.body.id);
},
async onDisable(context) {
const webhookId = await context.store.get<string>('webhookId');
if (webhookId) {
await httpClient.sendRequest({
method: HttpMethod.DELETE,
url: `${lobstermailCommon.baseUrl}/v1/webhooks/${webhookId}`,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: context.auth.secret_text,
},
});
}
},
async run(context) {
const payload = context.payload.body as {
event: string;
timestamp: string;
data: {
id?: string;
inboxId?: string;
sender?: string;
recipients?: string[];
subject?: string;
threadId?: string;
sentAt?: string;
};
};
const data = payload.data ?? {};
if (payload.event !== 'email.sent') {
return [];
}
return [
{
event: payload.event,
email_id: data.id ?? null,
inbox_id: data.inboxId ?? null,
from: data.sender ?? null,
to: Array.isArray(data.recipients)
? data.recipients.join(', ')
: data.recipients ?? null,
subject: data.subject ?? null,
thread_id: data.threadId ?? null,
sent_at: data.sentAt ?? payload.timestamp ?? null,
},
];
},
});