{"id":22305696,"url":"https://github.com/muratgozel/mimetext","last_synced_at":"2025-05-15T17:09:45.054Z","repository":{"id":34981502,"uuid":"193976723","full_name":"muratgozel/MIMEText","owner":"muratgozel","description":"RFC-5322 compliant, fully typed and documented email message generator for javascript runtimes.","archived":false,"fork":false,"pushed_at":"2025-01-02T13:27:12.000Z","size":3189,"stargazers_count":94,"open_issues_count":12,"forks_count":36,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T20:11:17.863Z","etag":null,"topics":["amazon-ses","attachment","email","email-attachments","email-message-header","email-parsing","mime-message","mimetext","nodejs-library","rfc-2045","rfc-2049","rfc-2822"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muratgozel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"muratgozel","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-06-26T20:58:22.000Z","updated_at":"2025-03-21T15:55:52.000Z","dependencies_parsed_at":"2024-03-08T20:13:46.090Z","dependency_job_id":"7233984f-f549-4294-921e-a53f98d0b059","html_url":"https://github.com/muratgozel/MIMEText","commit_stats":{"total_commits":28,"total_committers":5,"mean_commits":5.6,"dds":0.1428571428571429,"last_synced_commit":"62b852e6ccbe5e216ac4d3ab0a67dacb705402f9"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratgozel%2FMIMEText","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratgozel%2FMIMEText/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratgozel%2FMIMEText/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratgozel%2FMIMEText/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muratgozel","download_url":"https://codeload.github.com/muratgozel/MIMEText/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730069,"owners_count":20986404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-ses","attachment","email","email-attachments","email-message-header","email-parsing","mime-message","mimetext","nodejs-library","rfc-2045","rfc-2049","rfc-2822"],"created_at":"2024-12-03T19:12:48.356Z","updated_at":"2025-04-07T21:15:55.198Z","avatar_url":"https://github.com/muratgozel.png","language":"TypeScript","funding_links":["https://patreon.com/muratgozel","https://patreon.com/muratgozel?utm_medium=organic\u0026utm_source=github_repo\u0026utm_campaign=github\u0026utm_content=join_link","https://github.com/sponsors/muratgozel"],"categories":[],"sub_categories":[],"readme":"# MIMEText\nRFC-5322 compliant, fully typed and documented email message generator for javascript runtimes.\n\n\u003e Earlier specification RFC-2822 obsoleted by RFC-5322, therefore this library aims to be fully compliant with RFC-5322 and it's decendant specifications.\n\n## Installation\n### npm\nIt's published on [npm](https://www.npmjs.com/package/mimetext). Any package manager compatible with it, should work:\n```sh\nnpm i mimetext\n# or\npnpm add mimetext\n# or\nyarn add mimetext\n```\n\n### Standalone Browser Script\nThere is an [iife version](dist/mimetext.iife.js) (immediatly invoked function). This file includes polyfills and transforms that is neccessary to work on almost all browsers. Use it in your html documents but be aware of its size (~50kb).\n```html\n\u003cscript type=\"text/javascript\" src=\"/path/to/mimetext.iife.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    console.log(window.MimeText)\n\u003c/script\u003e\n```\n\n### Google Apps Script\nThere is a special export that is compatible with Google Apps Script environment. Use [gas.cjs](https://github.com/muratgozel/MIMEText/blob/master/dist/gas.cjs) as necessary.\n\n## Usage\nThe code is optimized for different environments such as node, browser and gas (Google Apps Script). Therefore, the library has three corresponding exports:\n```ts\nimport { createMimeMessage } from 'mimetext/node'\nimport { createMimeMessage } from 'mimetext/browser'\nimport { createMimeMessage } from 'mimetext/gas'\n// defaults to node export\nimport { createMimeMessage } from 'mimetext'\n```\nThey all have the same API but minor internal differences. Apart from environment, it can be imported as commonjs module too:\n```ts\nconst { createMimeMessage } = require('mimetext')\nconst { createMimeMessage } = require('mimetext')\nconst { createMimeMessage } = require('mimetext')\n// defaults to node export\nconst { createMimeMessage } = require('mimetext')\n```\n\n### Simple Email Message\nHere is a simple plain text email message:\n```js\nimport { createMimeMessage } from 'mimetext'\n\nconst msg = createMimeMessage()\nmsg.setSender({name: 'Lorem Ipsum', addr: 'lorem@ipsum.com'})\nmsg.setRecipient('foobor@test.com')\nmsg.setSubject('🚀 Issue 49!')\nmsg.addMessage({\n    contentType: 'text/plain',\n    data: `Hi,\nI'm a simple text.`\n})\nconst raw = msg.asRaw()\n\n/*\nDate: Sun, 24 Oct 2021 04:50:32 +0000\nFrom: \"Lorem Ipsum\" \u003clorem@ipsum.com\u003e\nTo: \u003cfoobor@test.com\u003e\nMessage-ID: \u003cis6jcakaj6p-1635051032602@ipsum.com\u003e\nSubject: =?utf-8?B?8J+agCBJc3N1ZSA0OSE=?=\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\n\nHi,\nI'm a simple text.\n*/\n```\n\n### APIs for Adding Different Kind and Way of Recipients\n```js\nmsg.setTo('first@last.com')\nmsg.setCc('first@last.com')\nmsg.setBcc('first@last.com')\n\n// \"To\" by default\nmsg.setRecipient('Firstname Lastname \u003cfirst@last.com\u003e')\n// but you can still specify other kinds\nmsg.setRecipient('Firstname Lastname \u003cfirst@last.com\u003e', {type: 'Cc'})\n// all as object\nmsg.setRecipient({\n    addr: 'first@last.com', \n    name: 'Firstname Lastname', \n    type: 'Bcc'\n})\n\n// multiple recipients, each as argument\nmsg.setRecipients(\n    'test@mail.com', \n    'Firstname Lastname \u003cfirst@last.com\u003e', \n    {addr: 'multiple@mail.com'}\n)\n```\n\n### HTML Message With Plain Text Fallback And Attachments\nBoth html and plain text version of a message can be set and attachments can be added. Here is a more complex example:\n```js\nconst msg = createMimeMessage()\n\nmsg.setSender('sender@mail.com')\nmsg.setRecipients('recipient@mail.com')\nmsg.setSubject('Testing MimeText 🐬 (Plain Text + HTML With Mixed Attachments)')\n\nmsg.addMessage({\n    contentType: 'text/plain',\n    data: 'Hello there,' + EOL + EOL +\n        'This is a test email sent by MimeText test suite.'\n})\nmsg.addMessage({\n    contentType: 'text/html',\n    data: 'Hello there,\u003cbr\u003e\u003cbr\u003e' +\n        'This is a test email sent by \u003cb\u003eMimeText\u003c/b\u003e test suite.\u003cbr\u003e\u003cbr\u003e' +\n        'The term MimeText above supposed to be bold. Are you able to see it?\u003cbr\u003e\u003cbr\u003e' +\n        'Below, there should be a small image that contains little black dots:\u003cbr\u003e\u003cbr\u003e' +\n        // using an inline attachment id here:\n        '\u003cimg src=\"cid:dots123456\"\u003e\u003cbr\u003e\u003cbr\u003e' +\n        'Best regards.'\n})\n\n// and the inline attachment:\nmsg.addAttachment({\n    inline: true,\n    filename: 'dots.jpg',\n    contentType: 'image/jpg',\n    data: '...base64 encoded data...',\n    headers: {'Content-ID': 'dots123456'}\n})\n\n// two more attachments but they aren't inlined, they are attached\nmsg.addAttachment({\n    filename: 'sample.jpg',\n    contentType: 'image/jpg',\n    data: '...base64 encoded data...'\n})\nmsg.addAttachment({\n    filename: 'sample.txt',\n    contentType: 'text/plain',\n    data: '...base64 encoded data...'\n})\n\nconst raw = msg.asRaw()\n\n/*\nDate: Sun, 26 Mar 2023 13:27:15 +0000\nFrom: \u003csender@mail.com\u003e\nTo: \u003crecipient@mail.com\u003e\nMessage-ID: \u003cvrye3zjqd@gozel.com.tr\u003e\nSubject: =?utf-8?B?VGVzdGluZyBNaW1lVGV4dCDwn5CsIChQbGFpbiBUZXh0ICsgSFRNTCBXaXRoIE1peGVkIEF0dGFjaG1lbnRzKQ==?=\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=giev1zqo579\n\n--giev1zqo579\nContent-Type: multipart/related; boundary=hl6rtnn5jq\n\n--hl6rtnn5jq\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\nHello there,\u003cbr\u003e\u003cbr\u003eThis is a test email sent by \u003cb\u003eMimeText\u003c/b\u003e test suite.\u003cbr\u003e\u003cbr\u003eThe term MimeText above supposed to be bold. Are you able to see it?\u003cbr\u003e\u003cbr\u003eBelow, there should be a small image that contains little black dots:\u003cbr\u003e\u003cbr\u003e\u003cimg src=\"cid:dots123456\"\u003e\u003cbr\u003e\u003cbr\u003eBest regards.\n\n--hl6rtnn5jq\nContent-ID: \u003cdots123456\u003e\nContent-Type: image/jpg; name=\"dots.jpg\"\nContent-Transfer-Encoding: base64\nContent-Disposition: inline; filename=\"dots.jpg\"\n\n/9j/4AAQSkZJRgABAgEASABIAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQ...........BPwAp/9k=\n--hl6rtnn5jq--\n--giev1zqo579\nContent-Type: image/jpg; name=\"sample.jpg\"\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; filename=\"sample.jpg\"\n\n/9j/4AAQSkZJRgABAg...........befPb4N8Hn4A/9k=\n\n--giev1zqo579\nContent-Type: text/plain; name=\"sample.txt\"\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; filename=\"sample.txt\"\n\nSGVsbG8gdGhlcmUu\n--giev1zqo579--\n*/\n```\n\n### Encoding The Output\nService providers may ask for the encoded version of a message. In that case use the `.asEncoded()` call instead of `.asRaw()`:\n```ts\n// base64-websafe encoded message\n// it first gets the raw version and then encodes it.\nmsg.asEncoded()\n```\n\n## Use Cases\n- Email delivery services might ask you to prepare an email message in raw format before sending it with their email client.\n- When email message testing or parsing needed.\n- Preference.\n\nHere are two examples that uses **Amazon SES** and **Google Gmail** for email sending.\n\n### Amazon SES with AWS-SDK Client V1\n```js\n// install with npm i @aws-sdk/client-ses\n\nconst { SESClient, SendRawEmailCommand } = require('@aws-sdk/client-ses')\nconst ses = new SESClient({ region: 'YOUR_REGION' })\nconst { Buffer } = require('node:buffer')\nconst { createMimeMessage } = require('mimetext')\n\nconst message = createMimeMessage()\nmessage.setSender('sender@email.com')\nmessage.setTo('person1@email.com')\nmessage.setSubject('Weekly Newsletter 49 Ready 🚀')\nmessage.addAttachment({\n  filename: 'bill.pdf',\n  contentType: 'application/pdf',\n  data: '...base64 encoded data...'\n})\nmessage.addMessage({\n  contentType: 'text/html',\n  data: 'Hello \u003cb\u003eJohn\u003c/b\u003e.'\n})\n\n// send\nconst params = {\n  Destinations: message.getRecipients({type: 'to'})\n    .map(mailbox =\u003e mailbox.addr),\n  RawMessage: {\n      // the raw message data needs to be sent as uint8array\n      Data: Buffer.from(message.asRaw(), 'utf8')\n  },\n  Source: message.getSender().addr\n}\nconst result = await ses.send(new SendRawEmailCommand(params))\n\n// expect result.MessageId\n```\n\n### Amazon SES with AWS-SDK Client V2\n```js\n// install with npm i @aws-sdk/client-sesv2\n\nconst { SESv2Client, SendEmailCommand } = require('@aws-sdk/client-ses')\nconst ses = new SESv2Client({ region: 'YOUR_REGION' })\nconst { Buffer } = require('node:buffer')\nconst { createMimeMessage } = require('mimetext')\n\nconst message = createMimeMessage()\nmessage.setSender('sender@email.com')\nmessage.setTo('person1@email.com')\nmessage.setSubject('Weekly Newsletter 49 Ready 🚀')\nmessage.addAttachment({\n    filename: 'bill.pdf',\n    contentType: 'application/pdf',\n    data: '...base64 encoded data...'\n})\nmessage.addMessage({\n    contentType: 'text/html',\n    data: 'Hello \u003cb\u003eJohn\u003c/b\u003e.'\n})\n\nconst params = {\n    FromEmailAddress: message.getSender().addr,\n    Destination: {\n        ToAddresses: message.getRecipients()\n            .map((box) =\u003e box.addr)\n    },\n    Content: {\n        Raw: {\n            Data: Buffer.from(message.asRaw(), 'utf8')\n        }\n    }\n}\nconst result = await ses.send(new SendEmailCommand(params))\n\n// result.MessageId\n```\n\n### Google Gmail with googleapis-sdk\n\n```js\n// init google api sdk\nconst {google} = require('googleapis')\nconst {createMimeMessage} = require('mimetext')\n\nconst message = createMimeMessage()\nmessage.setSender('sender@email.com')\nmessage.setTo('person1@email.com')\nmessage.setSubject('Weekly Newsletter 49 Ready 🚀')\nmessage.addAttachment({\n    filename: 'bill.pdf',\n    contentType: 'application/pdf',\n    data: '...base64 encoded data...'\n})\nmessage.addMessage({\n    contentType: 'text/html',\n    data: 'Hello \u003cb\u003eJohn\u003c/b\u003e.'\n})\n\n// send\ngoogle.auth\n  .getClient({scopes: ['https://www.googleapis.com/auth/gmail.send']})\n  .then(function(client) {\n    client.subject = 'sender@email.com'\n\n    const gmail = google.gmail({ version: 'v1', auth: client })\n\n    gmail.users.messages\n      .send({\n        userId: 'me',\n        requestBody: {\n          raw: message.asEncoded()\n        }\n      })\n      .then(function(result) {\n        // expect result.id\n      })\n      .catch(function(err) {\n\n      })\n  })\n```\n\n## Error Handling\nMost of the methods raises `MIMETextError` in case of invalid input. You can catch and handle them accordingly.\n```js\ntry {\n  message.setTo({prop: 'invalid'})\n} catch (e) {\n  e instanceof MIMETextError === true\n}\n```\n\n## Relevant Specifications\n- [RFC-5322](https://datatracker.ietf.org/doc/html/rfc5322)\n- [RFC-2045](https://datatracker.ietf.org/doc/html/rfc2045)\n- [RFC-2046](https://datatracker.ietf.org/doc/html/rfc2046)\n- [RFC-2047](https://datatracker.ietf.org/doc/html/rfc2047)\n- [RFC-2048](https://datatracker.ietf.org/doc/html/rfc2048)\n- [RFC-2049](https://datatracker.ietf.org/doc/html/rfc2049)\n\n## Contributing\nIf you're interested in contributing, read the [CONTRIBUTING.md](https://github.com/muratgozel/muratgozel/blob/main/CONTRIBUTING.md) first, please.\n\n---\n\nThanks for the attention 💙 Any amount of support on [patreon](https://patreon.com/muratgozel?utm_medium=organic\u0026utm_source=github_repo\u0026utm_campaign=github\u0026utm_content=join_link) or [github](https://github.com/sponsors/muratgozel) will return you back as bug fixes, new features and bits and bytes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratgozel%2Fmimetext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuratgozel%2Fmimetext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratgozel%2Fmimetext/lists"}