enterprise-basics
Version:
A utility library for enterprise applications. It streamlines common business tasks by providing functions to process delimited and Excel files, generate professional PDFs, and handle email communications with attachments.
72 lines (71 loc) • 1.9 kB
TypeScript
export interface Attachment {
filename?: string;
fileBytes?: Uint8Array;
contentType?: string;
}
export interface EmailWithAttachment {
from: string;
to: string[];
cc?: string[];
subject: string;
body: string;
attachments?: Attachment[] | null | undefined;
}
export interface SMTPConfig {
host: string;
port: number;
auth: {
user: string;
pass: string;
};
}
/**
* Class for sending emails using SMTP.
* Provides methods to send emails with optional attachments.
*
* @example
* // Create an instance with SMTP configuration
* const emailClient = new EmailClient({
* host: 'smtp.example.com',
* port: 587,
* auth: { user: 'user', pass: 'pass' }
* });
*
* // Send an email
* await emailClient.sendEmail({
* from: 'sender@example.com',
* to: ['recipient@example.com'],
* subject: 'Test Email',
* body: 'This is a test email with attachment',
* attachments: [{
* filename: 'test.pdf',
* fileBytes: new Uint8Array([255, 255]),
* contentType: 'application/pdf'
* }]
* });
*/
export declare class EmailClient {
private _smtpConfig;
private _isDev;
/**
* Creates a new instance of EmailClient.
*
* @param {SMTPConfig} smtpConfig - SMTP server configuration
*
* @throws {Error} If validation of SMTP configuration fails
*/
constructor(smtpConfig: SMTPConfig, isDev?: boolean);
/**
* Sends an email with optional attachments.
*
* @param {EmailWithAttachment} email - Email content including sender, recipients, subject, body, and attachments
*
* @returns {Promise<void>} Resolves when email is sent successfully
*
* @throws {Error} If:
* - Input validation fails
* - Email client creation fails
* - Sending email fails
*/
sendEmail(email: EmailWithAttachment): Promise<void>;
}