Skip to main content
Home

latest

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

This package works with Cloudflare Workers, Node.js, Deno, BrowsersIt 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
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
64%
Published
a year 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();

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@skymethod/mimetext

Import symbol

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

Import directly with a jsr specifier

import * as mimetext from "jsr:@skymethod/mimetext";

Add Package

pnpm i jsr:@skymethod/mimetext
or (using pnpm 10.8 or older)
pnpm dlx jsr add @skymethod/mimetext

Import symbol

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

Add Package

yarn add jsr:@skymethod/mimetext
or (using Yarn 4.8 or older)
yarn dlx jsr add @skymethod/mimetext

Import symbol

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

Add Package

npx jsr add @skymethod/mimetext

Import symbol

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

Add Package

bunx jsr add @skymethod/mimetext

Import symbol

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