Constructors

  • Creates a new email instance.

    Parameters

    • envelope: Envelope

      The envelope containing sender and recipient details.

    • headers: Record<string, string | string[]>

      The headers of the email.

    • body: string

      The plain text body of the email.

    • Optionalattachments: Attachment[]

      Optional attachments for the email.

    Returns Email

    0.0.1

Properties

attachments?: Attachment[]

The attachments associated with the email. Defaults to an empty array if not provided.

0.0.1

body: string

The plain text body of the email.

0.0.1

envelope: Envelope

The envelope containing sender and recipient details.

0.0.1

headers: Record<string, string | string[]>

The headers of the email, stored as key-value pairs. Header names are case-insensitive.

0.0.1

Methods

  • Adds a new header or appends to an existing header. If the header already exists, it is converted to an array.

    Parameters

    • name: string

      The name of the header.

    • value: string

      The value to add to the header.

    Returns void

    const email = new Email(envelope, {}, 'Hello');
    email.addHeader('X-Custom-Header', 'Value1');
    email.addHeader('X-Custom-Header', 'Value2');
    console.log(email.getHeader('X-Custom-Header')); // Output: ['Value1', 'Value2']

    0.0.1

  • Retrieves the body of the email. If the email contains both plain text and HTML, plain text is preferred.

    Returns string

    The email body.

    const email = new Email(envelope, {}, 'Hello, world!');
    console.log(email.getBody()); // Output: 'Hello, world!'

    0.0.1

  • Retrieves a header value by name (case-insensitive).

    Parameters

    • name: string

      The name of the header to retrieve.

    Returns undefined | string | string[]

    The header value, or undefined if not found.

    const email = new Email(envelope, { 'subject': 'Subject String' });
    console.log(email.getHeader('Subject')); // Output: 'Subject String'

    0.0.1

  • Removes a header by name (case-insensitive).

    Parameters

    • name: string

      The name of the header to remove.

    Returns void

    const email = new Email(envelope, { 'X-Test': 'value' }, 'Hello');
    email.removeHeader('X-Test');
    console.log(email.getHeader('X-Test')); // Output: undefined

    0.0.1

  • Returns the email as a string in the IMF format.

    Returns string

    The formatted email as a string.

    const email = new Email(envelope, { subject: 'Test' }, 'Hello');
    console.log(email.toString());
    // Output:
    // Subject: Test
    //
    // Hello

    0.0.1