Skip to main content

latest

Raw email generator, port of https://github.com/muratgozel/MIMEText. Useful when working with Amazon SES, Gmail API or Cloudflare Email Workers.

Works with
It is unknown whether this package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
64%
Published
4 months ago (0.0.6)

mimetext

Raw email generator, port of https://github.com/muratgozel/MIMEText

Useful when working with Amazon SES, Google Gmail or Cloudflare Email Workers.

Usage

import { createMimeMessage } from 'jsr:@skymethod/mimetext';

const msg = createMimeMessage();
msg.setSender({ name: 'Example Sender', addr: 'from@example.com' });
msg.setRecipient('to@example.com');
msg.setSubject('🚀 Hello world!');
msg.addMessage({ contentType: 'text/plain', data: `Hi,\nThis is a simple text message.` });

const raw = msg.asRaw();

Usage (more complex)

import { createMimeMessage } from 'jsr:@skymethod/mimetext';

const msg = createMimeMessage();
msg.setSender('from@example.com');
msg.setRecipient('Firstname Lastname <first@example.com>'); // 'To' field by default
msg.setRecipient('Firstname Lastname <second@example.com>', { type: 'Cc' }); // To, Cc, Bcc
msg.setRecipient({ addr: 'third@example.com', name: 'Firstname Lastname', type: 'Bcc' });
msg.setSubject('Testing 🐬 (Text/HTML/Mixed attachments)');

// support both plain-text and html
msg.addMessage({
    contentType: 'text/plain',
    data: 'Hello there,\n\nThis is a the text part!',
});
msg.addMessage({
    contentType: 'text/html',
    data: 'Hello there,<br><br>' +
        'This is the <b>html part</b>.<br><br>' +
        'The term \'html part\' above should be bold.<br><br>' +
        'Below, there should be a small image:<br><br>' +
        '<img src="cid:dots123456">', // specify inline attachment's content id (declared below)
});

// attachments
msg.addAttachment({
    filename: 'sample.jpg',
    contentType: 'image/jpg',
    data: '...base64 encoded data...',
});
msg.addAttachment({
    filename: 'sample.txt',
    contentType: 'text/plain',
    data: '...base64 encoded data...',
});
msg.addAttachment({
    inline: true, // this is inline attachment!
    filename: 'dots.jpg',
    contentType: 'image/jpg',
    data: '...base64 encoded data...',
    headers: { 'Content-ID': 'dots123456' }, // referenced in html part
});

const raw = msg.asRaw();

Add Package

deno add @skymethod/mimetext

Import symbol

import * as mod from "@skymethod/mimetext";

Add Package

npx jsr add @skymethod/mimetext

Import symbol

import * as mod from "@skymethod/mimetext";

Add Package

yarn dlx jsr add @skymethod/mimetext

Import symbol

import * as mod from "@skymethod/mimetext";

Add Package

pnpm dlx jsr add @skymethod/mimetext

Import symbol

import * as mod from "@skymethod/mimetext";

Add Package

bunx jsr add @skymethod/mimetext

Import symbol

import * as mod from "@skymethod/mimetext";