{"name":"emailjs","description":"send text/html emails and attachments (files, streams and strings) from node.js to any smtp server","version":"5.0.3","author":{"name":"eleith"},"contributors":[{"name":"izuzak"},{"name":"Hiverness"},{"name":"mscdex"},{"name":"jimmybergman"},{"name":"zackschuster"}],"repository":{"type":"git","url":"git+ssh://git@github.com/eleith/emailjs.git"},"type":"module","devDependencies":{"@eslint/js":"^9.17.0","@types/mailparser":"3.4.0","@types/node":"^22.10.2","@types/smtp-server":"3.5.7","@vitest/coverage-v8":"4.0.15","eslint":"^9.17.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","mailparser":"3.9.1","prettier":"^3.4.2","smtp-server":"3.17.1","ts-node":"^10.9.2","typescript":"^5.7.2","typescript-eslint":"^8.18.1","vitest":"4.0.15"},"peerDependencies":{"typescript":">=5.0.0"},"peerDependenciesMeta":{"typescript":{"optional":true}},"resolutions":{"nodemailer":"6.7.4"},"engines":{"node":">=18"},"main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc","lint":"eslint src/*.ts","test":"vitest run","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"license":"MIT","gitHead":"de1adbb472e1497edef8766675b0f25714ecfcce","_id":"emailjs@5.0.3","bugs":{"url":"https://github.com/eleith/emailjs/issues"},"homepage":"https://github.com/eleith/emailjs#readme","_nodeVersion":"22.23.2","_npmVersion":"12.0.2","dist":{"integrity":"sha512-Y47oNF5Geurb8GnmST2b+EK8mDLKoDFySxsvZb6YMcNbvdxpjd9FaLQ80p38lUVhq50knveOhkH/c/4afJSFxQ==","shasum":"3527970d3bc3d1f4a9e3b8b41a2265683e162709","tarball":"http://registry-npm.ywwl.com/emailjs/download/emailjs-5.0.3.tgz","fileCount":75,"unpackedSize":325422,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emailjs@5.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDpdEiypx2UE5IpKGSF+Ee1zgeTt8DOVDwYb1cD55dtnAIhAPrhTcyxCAsRfqrfE/feRKEZAYs76ShzEDQTszNdDBRp"}],"size":59217,"noattachment":false,"key":"/emailjs/-/emailjs-5.0.3.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:db8c1271-ab16-4647-bb70-13f3bf6aa876"}},"directories":{},"maintainers":[{"name":"eleith","email":"online-npm@eleith.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emailjs_5.0.3_1787772593808_0.3756454761324588"},"_hasShrinkwrap":false,"readme":"# emailjs 📧✨\n\nSend emails with ease!\n\nThis library lets you send rich HTML emails,\nattachments (from files, streams, or strings), and plain text messages to any\nSMTP server.\n\n[![checks](https://github.com/eleith/emailjs/actions/workflows/check.yml/badge.svg)](https://github.com/eleith/emailjs/actions/workflows/check.yml)\n\n## What's to expect from emailjs? 🚀\n\n* **SSL and TLS Support:** Secure connections to your SMTP servers.\n* **Authentication Galore:** Supports popular SMTP authentication methods like\n`PLAIN`, `LOGIN`, `CRAM-MD5`, and `XOAUTH2`.\n* **Asynchronous Sending:** Emails are queued and sent in the\nbackground.\n* **Rich Content:** Send HTML emails and include multiple attachments.\n* **Flexible Attachments:** Attachments can be files, data streams, or plain\nstrings.\n* **UTF-8 Ready:** Full support for UTF-8 in headers and body.\n* **Built-in Type Declarations:** first-class TypeScript support.\n* **Greylisting Awareness:** Automatically handles\n[greylisting](http://projects.puremagic.com/greylisting/whitepaper.html) to\nimprove deliverability.\n\n## Get Started! 🛠️\n\n### Installing\n\nIt's super simple!\n\n```bash\nnpm install emailjs\n```\n\n### Requirements\n\n* Access to an SMTP Server.\n* If your email service (like Gmail) uses two-step verification, you'll need an\napplication-specific password.\n\n### Quick Examples 🧑‍💻\n\nHere's how easy it is to send emails:\n\n#### Text-Only Emails\n\n```javascript\nimport { SMTPClient } from 'emailjs';\n\nconst client = new SMTPClient({\n    user: 'your-username',\n    password: 'your-password',\n    host: 'smtp.your-email.com',\n    ssl: true, // Use SSL for secure connection\n});\n\nasync function sendMyEmail() {\n    try {\n        const message = await client.sendAsync({\n            text: 'Hello from emailjs! This is a test message.',\n            from: 'You <your-email@example.com>',\n            to: 'Someone <someone@example.com>',\n            subject: 'Exciting News from emailjs! 🎉',\n        });\n        console.log('Email sent successfully:', message);\n    } catch (err) {\n        console.error('Failed to send email:', err);\n    } finally {\n        client.smtp.close(); // Don't forget to close the connection!\n    }\n}\n\nsendMyEmail();\n```\n\n#### HTML Emails & Attachments\n\n```javascript\nimport { SMTPClient, Message } from 'emailjs';\n\nconst client = new SMTPClient({\n    user: 'your-username',\n    password: 'your-password',\n    host: 'smtp.your-email.com',\n    tls: true,\n});\n\nasync function sendRichEmail() {\n    const htmlContent = `\n        <h1>Greetings!</h1>\n        <p>This is an <b>HTML email</b> with a lovely picture and an attachment.</p>\n        <img src=\"cid:my-image\" alt=\"Embedded Image\" width=\"150\" height=\"100\">\n        <p>Check out the attached file!</p>\n    `;\n\n    const message = new Message({\n        from: 'You <your-email@example.com>',\n        to: 'Someone <someone@example.com>',\n        subject: 'Your Awesome HTML Email! 🖼️📄',\n        attachment: [\n            {\n                data: htmlContent,\n                alternative: true, // This part is the HTML body\n                contentType: 'text/html',\n            },\n            {\n                path: 'path/to/your/document.pdf', // Attach a file from disk\n                type: 'application/pdf',\n                name: 'document.pdf',\n            },\n            {\n                path: 'path/to/your/image.jpg', // Embed an image for the HTML\n                type: 'image/jpeg',\n                name: 'cool_image.jpg',\n                // Reference in HTML with cid:my-image\n                headers: { 'Content-ID': '<my-image>' },\n            },\n        ],\n    });\n\n    try {\n        await client.sendAsync(message);\n        console.log('Rich email sent successfully!');\n    } catch (err) {\n        console.error('Failed to send rich email:', err);\n    } finally {\n        client.smtp.close();\n    }\n}\n\nsendRichEmail();\n```\n\n## API Reference 📖\n\nThe `emailjs` library is fully typed, here is a brief overview of most likely to\nbe used methods\n\n### `new SMTPClient(options)`\n\nCreate a new client instance to connect to your SMTP server.\n\n```javascript\nconst options = {\n    user: 'your-username', // 🔑 Username for logging into SMTP\n    password: 'your-password', // 🤫 Password for logging into SMTP\n    host: 'smtp.your-email.com', // 🌐 SMTP server host (defaults to 'localhost')\n    port: 587, // 🔌 SMTP port (defaults: 25 unencrypted, 465 SSL, 587 TLS)\n    ssl: true, // 🔒 Boolean or object for immediate SSL connection\n    tls: true, // 🔐 Boolean or object (see typescript types) to initiate STARTTLS\n    timeout: 5000, // ⏳ Max milliseconds to wait for SMTP responses\n    domain: 'your-domain.com', // 🏠 Domain to greet SMTP with (defaults to os.hostname)\n    authentication: ['PLAIN', 'LOGIN'], // 🤝 Preferred authentication methods\n    logger: console, // 📝 Override the built-in logger (e.g., custom logging)\n};\n```\n\n### `SMTPClient#send(message, callback)`\n\nSends an email message. You can pass a `Message` instance or a headers object.\n\n```javascript\nclient.send(messageObject, (err, details) => {\n    if (err) console.error(err);\n    else console.log('Message sent:', details);\n});\n```\n\n### `SMTPClient#sendAsync(message)`\n\na promise-based way to send emails! ✨\n\n```javascript\ntry {\n    const details = await client.sendAsync(messageObject);\n    console.log('Message sent:', details);\n} catch (err) {\n    console.error('Failed to send:', err);\n}\n```\n\n### `new Message(headers)`\n\nConstructs an RFC2822-compliant message object.\n\n```javascript\nconst headers = {\n    from: 'sender@example.com', // 💌 Sender (required!)\n    to: 'recipient@example.com', // 📬 Recipients (at least one of to, cc, or bcc)\n    cc: 'carbon-copy@example.com', // 👥 CC recipients\n    bcc: 'blind-copy@example.com', // 🕵️‍♀️ BCC recipients\n    subject: 'Your Subject Here', // 📝 Email subject\n    text: 'Plain text body.', // 🗒️ Plain text content\n    attachment: [{ data: 'Hello!' }], // 📎 One or more attachments\n};\n```\n\n### `Message#attach(options)`\n\nAdds an attachment to the message. Can be called multiple times.\n\n```javascript\nmessage.attach({\n    path: 'path/to/file.zip', // 📁 Path to a file on disk\n    data: 'Binary content as string or buffer', // 📄 Raw data\n    stream: fs.createReadStream('file.jpg'), // 🌊 A readable stream\n    type: 'application/zip', // MIME type\n    name: 'custom-name.zip', // Filename perceived by recipient\n    alternative: true, // attach inline as an alternative (e.g., HTML body)\n    inline: true, // If true, attached inline (e.g., for <img src=\"cid:...\">)\n    headers: { 'X-Custom-Header': 'value' }, // Custom attachment headers\n});\n```\n\n### `Message#checkValidity()`\n\nSynchronously validates that a `Message` is properly formed before sending.\n\n```javascript\nconst { isValid, validationError } = message.checkValidity();\nif (!isValid) {\n    console.error('Message is invalid:', validationError);\n}\n```\n\n## Authors ✍️\n\n* eleith\n* zackschuster\n\n## Testing 🧪\n\n```bash\n# Run all tests\nnpm test\n\n# Run tests with code coverage report\nnpm run test:coverage\n```\n\n## Development 🧑‍💻🌱\n\nfor a local smtp testing experience, use our\n[Mailpit](https://mailpit.axllent.org/) compose service\n\n### 1. Start Mailpit with Docker Compose\n\nEnsure you have Docker and Docker Compose installed.\n\n```bash\n# From the project root, start Mailpit\ndocker compose up\n```\n\nMailpit will be accessible via:\n\n* **Web UI:** `http://localhost:8025`\n* **SMTP Server:** `localhost:1025`\n\n### 2. Run Example Sending Scripts\n\nYou can use the provided scripts to send different types of emails to your local\nMailpit instance.\n\nFirst, make sure the `emailjs` library is built:\n\n```bash\nnpm run build\n```\n\nThen, run any of the example scripts:\n\n```bash\n# Send a plain text email\nnode scripts/send-text.js\n\n# Send an HTML email\nnode scripts/send-html.js\n\n# Send an email with attachments\nnode scripts/send-attachment.js\n```\n\nAfter running a script, open your Mailpit Web UI (`http://localhost:8025`) to\nsee the emails stream in! 📩\n\n","publish_time":1787772593962,"_cnpm_publish_time":1787772593962,"dist-tags":{"latest":"5.0.4"}}