{"id":13401024,"url":"https://github.com/eleith/emailjs","last_synced_at":"2025-05-14T00:07:30.299Z","repository":{"id":41977695,"uuid":"1403994","full_name":"eleith/emailjs","owner":"eleith","description":"html emails and attachments to any smtp server with nodejs","archived":false,"fork":false,"pushed_at":"2023-09-06T03:45:39.000Z","size":6813,"stargazers_count":2199,"open_issues_count":7,"forks_count":231,"subscribers_count":60,"default_branch":"main","last_synced_at":"2025-05-09T21:14:31.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","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/eleith.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2011-02-23T21:14:18.000Z","updated_at":"2025-05-08T04:22:06.000Z","dependencies_parsed_at":"2024-01-12T00:28:12.668Z","dependency_job_id":"166d5eb0-f154-4dd8-abc8-2c622d6a3b7f","html_url":"https://github.com/eleith/emailjs","commit_stats":{"total_commits":537,"total_committers":52,"mean_commits":"10.326923076923077","dds":"0.43202979515828677","last_synced_commit":"8b3c0b16f81e9ab2a3ca518cd893b3474f87cda6"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleith%2Femailjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleith%2Femailjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleith%2Femailjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleith%2Femailjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eleith","download_url":"https://codeload.github.com/eleith/emailjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043776,"owners_count":22005014,"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":[],"created_at":"2024-07-30T19:00:57.974Z","updated_at":"2025-05-14T00:07:30.283Z","avatar_url":"https://github.com/eleith.png","language":"HTML","readme":"# emailjs [![Test Status](https://github.com/eleith/emailjs/workflows/.github/workflows/test.yml/badge.svg)](https://github.com/eleith/emailjs/actions?query=workflow%3A.github%2Fworkflows%2Ftest.yml) [![Lint Status](https://github.com/eleith/emailjs/workflows/.github/workflows/lint.yml/badge.svg)](https://github.com/eleith/emailjs/actions?query=workflow%3A.github%2Fworkflows%2Flint.yml)\n\nsend emails, html and attachments (files, streams and strings) from node.js to any smtp server\n\n## INSTALLING\n\n    npm install emailjs\n\n## FEATURES\n\n- works with SSL and TLS smtp servers\n- supports smtp authentication ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')\n- emails are queued and the queue is sent asynchronously\n- supports sending html emails and emails with multiple attachments (MIME)\n- attachments can be added as strings, streams or file paths\n- supports utf-8 headers and body\n- built-in type declarations\n- automatically handles [greylisting](http://projects.puremagic.com/greylisting/whitepaper.html)\n\n## REQUIRES\n\n- auth access to an SMTP Server\n- if your service (ex: gmail) uses two-step authentication, use an application specific password\n\n## EXAMPLE USAGE - text only emails\n\n```js\nimport { SMTPClient } from 'emailjs';\n\nconst client = new SMTPClient({\n\tuser: 'user',\n\tpassword: 'password',\n\thost: 'smtp.your-email.com',\n\tssl: true,\n});\n\n// send the message and get a callback with an error or details of the message that was sent\nclient.send(\n\t{\n\t\ttext: 'i hope this works',\n\t\tfrom: 'you \u003cusername@your-email.com\u003e',\n\t\tto: 'someone \u003csomeone@your-email.com\u003e, another \u003canother@your-email.com\u003e',\n\t\tcc: 'else \u003celse@your-email.com\u003e',\n\t\tsubject: 'testing emailjs',\n\t},\n\t(err, message) =\u003e {\n\t\tconsole.log(err || message);\n\t}\n);\n```\n\n## EXAMPLE USAGE - using async/await\n\n```js\n// assuming top-level await for brevity\nimport { SMTPClient } from 'emailjs';\n\nconst client = new SMTPClient({\n\tuser: 'user',\n\tpassword: 'password',\n\thost: 'smtp.your-email.com',\n\tssl: true,\n});\n\ntry {\n\tconst message = await client.sendAsync({\n\t\ttext: 'i hope this works',\n\t\tfrom: 'you \u003cusername@your-email.com\u003e',\n\t\tto: 'someone \u003csomeone@your-email.com\u003e, another \u003canother@your-email.com\u003e',\n\t\tcc: 'else \u003celse@your-email.com\u003e',\n\t\tsubject: 'testing emailjs',\n\t});\n\tconsole.log(message);\n} catch (err) {\n\tconsole.error(err);\n}\n```\n\n## EXAMPLE USAGE - html emails and attachments\n\n```js\nimport { SMTPClient } from 'emailjs';\n\nconst client = new SMTPClient({\n\tuser: 'user',\n\tpassword: 'password',\n\thost: 'smtp.your-email.com',\n\tssl: true,\n});\n\nconst message = {\n\ttext: 'i hope this works',\n\tfrom: 'you \u003cusername@your-email.com\u003e',\n\tto: 'someone \u003csomeone@your-email.com\u003e, another \u003canother@your-email.com\u003e',\n\tcc: 'else \u003celse@your-email.com\u003e',\n\tsubject: 'testing emailjs',\n\tattachment: [\n\t\t{ data: '\u003chtml\u003ei \u003ci\u003ehope\u003c/i\u003e this works!\u003c/html\u003e', alternative: true },\n\t\t{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },\n\t],\n};\n\n// send the message and get a callback with an error or details of the message that was sent\nclient.send(message, function (err, message) {\n\tconsole.log(err || message);\n});\n\n// you can continue to send more messages with successive calls to 'client.send',\n// they will be queued on the same smtp connection\n\n// or instead of using the built-in client you can create an instance of 'smtp.SMTPConnection'\n```\n\n## EXAMPLE USAGE - sending through outlook\n\n```js\nimport { SMTPClient, Message } from 'emailjs';\n\nconst client = new SMTPClient({\n\tuser: 'user',\n\tpassword: 'password',\n\thost: 'smtp-mail.outlook.com',\n\ttls: {\n\t\tciphers: 'SSLv3',\n\t},\n});\n\nconst message = new Message({\n\ttext: 'i hope this works',\n\tfrom: 'you \u003cusername@outlook.com\u003e',\n\tto: 'someone \u003csomeone@your-email.com\u003e, another \u003canother@your-email.com\u003e',\n\tcc: 'else \u003celse@your-email.com\u003e',\n\tsubject: 'testing emailjs',\n\tattachment: [\n\t\t{ data: '\u003chtml\u003ei \u003ci\u003ehope\u003c/i\u003e this works!\u003c/html\u003e', alternative: true },\n\t\t{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },\n\t],\n});\n\n// send the message and get a callback with an error or details of the message that was sent\nclient.send(message, (err, message) =\u003e {\n\tconsole.log(err || message);\n});\n```\n\n## EXAMPLE USAGE - attaching and embedding an image\n\n```js\nimport { SMTPClient, Message } from 'emailjs';\n\nconst client = new SMTPClient({\n\tuser: 'user',\n\tpassword: 'password',\n\thost: 'smtp-mail.outlook.com',\n\ttls: {\n\t\tciphers: 'SSLv3',\n\t},\n});\n\nconst message = new Message({\n\ttext: 'i hope this works',\n\tfrom: 'you \u003cusername@outlook.com\u003e',\n\tto: 'someone \u003csomeone@your-email.com\u003e, another \u003canother@your-email.com\u003e',\n\tcc: 'else \u003celse@your-email.com\u003e',\n\tsubject: 'testing emailjs',\n\tattachment: [\n\t\t{\n\t\t\tdata:\n\t\t\t\t'\u003chtml\u003ei \u003ci\u003ehope\u003c/i\u003e this works! here is an image: \u003cimg src=\"cid:my-image\" width=\"100\" height =\"50\"\u003e \u003c/html\u003e',\n\t\t},\n\t\t{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },\n\t\t{\n\t\t\tpath: 'path/to/image.jpg',\n\t\t\ttype: 'image/jpg',\n\t\t\theaders: { 'Content-ID': '\u003cmy-image\u003e' },\n\t\t},\n\t],\n});\n\n// send the message and get a callback with an error or details of the message that was sent\nclient.send(message, (err, message) =\u003e {\n\tconsole.log(err || message);\n});\n```\n\n# API\n\n## new SMTPClient(options)\n\n```js\n// options is an object with the following recognized schema:\nconst options = {\n\tuser, // username for logging into smtp\n\tpassword, // password for logging into smtp\n\thost, // smtp host (defaults to 'localhost')\n\tport, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`)\n\tssl, // boolean or object (if true or object, ssl connection will be made)\n\ttls, // boolean or object (if true or object, starttls will be initiated)\n\ttimeout, // max number of milliseconds to wait for smtp responses (defaults to 5000)\n\tdomain, // domain to greet smtp with (defaults to os.hostname)\n\tauthentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')\n\tlogger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)\n};\n// ssl/tls objects are an abbreviated form of [`tls.connect`](https://nodejs.org/dist/latest-v14.x/docs/api/tls.html#tls_tls_connect_options_callback)'s options\n// the missing items are: `port`, `host`, `path`, `socket`, `timeout` and `secureContext`\n// NOTE: `host` is trimmed before being used to establish a connection;\n// however, the original untrimmed value will still be visible in configuration.\n```\n\n## SMTPClient#send(message, callback)\n\n```js\n// message can be a smtp.Message (as returned by email.message.create)\n// or an object identical to the first argument accepted by email.message.create\n\n// callback will be executed with (err, message)\n// either when message is sent or an error has occurred\n```\n\n## new Message(headers)\n\n```js\n// headers is an object with the following recognized schema:\nconst headers = {\n\tfrom, // sender of the format (address or name \u003caddress\u003e or \"name\" \u003caddress\u003e)\n\tto, // recipients (same format as above), multiple recipients are separated by a comma\n\tcc, // carbon copied recipients (same format as above)\n\tbcc, // blind carbon copied recipients (same format as above)\n\ttext, // text of the email\n\tsubject, // string subject of the email\n\tattachment, // one attachment or array of attachments\n};\n// the `from` field is required.\n// at least one `to`, `cc`, or `bcc` header is also required.\n// you can also add whatever other headers you want.\n```\n\n## Message#attach(options)\n\nCan be called multiple times, each adding a new attachment.\n\n```js\n// options is an object with the following recognized schema:\nconst options = {\n\t// one of these fields is required\n\tpath, // string to where the file is located\n\tdata, // string of the data you want to attach\n\tstream, // binary stream that will provide attachment data (make sure it is in the paused state)\n\t// better performance for binary streams is achieved if buffer.length % (76*6) == 0\n\t// current max size of buffer must be no larger than Message.BUFFERSIZE\n\n\t// optionally these fields are also accepted\n\ttype, // string of the file mime type\n\tname, // name to give the file as perceived by the recipient\n\tcharset, // charset to encode attatchment in\n\tmethod, // method to send attachment as (used by calendar invites)\n\talternative, // if true, will be attached inline as an alternative (also defaults type='text/html')\n\tinline, // if true, will be attached inline\n\tencoded, // set this to true if the data is already base64 encoded, (avoid this if possible)\n\theaders, // object containing header=\u003evalue pairs for inclusion in this attachment's header\n\trelated, // an array of attachments that you want to be related to the parent attachment\n};\n```\n\n## Message#checkValidity()\n\nSynchronously validate that a Message is properly formed.\n\n```js\nconst message = new Message(options);\nconst { isValid, validationError } = message.checkValidity();\nif (isValid) {\n\t// ...\n} else {\n\t// first error encountered\n\tconsole.error(validationError);\n}\n```\n\n## new SMTPConnection(options={})\n\n```js\n// options is an object with the following recognized schema:\nconst options = {\n\tuser, // username for logging into smtp\n\tpassword, // password for logging into smtp\n\thost, // smtp host (defaults to 'localhost')\n\tport, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`)\n\tssl, // boolean or object (if true or object, ssl connection will be made)\n\ttls, // boolean or object (if true or object, starttls will be initiated)\n\ttimeout, // max number of milliseconds to wait for smtp responses (defaults to 5000)\n\tdomain, // domain to greet smtp with (defaults to os.hostname)\n\tauthentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')\n\tlogger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)\n};\n// ssl/tls objects are an abbreviated form of [`tls.connect`](https://nodejs.org/dist/latest-v14.x/docs/api/tls.html#tls_tls_connect_options_callback)'s options\n// the missing items are: `port`, `host`, `path`, `socket`, `timeout` and `secureContext`\n// NOTE: `host` is trimmed before being used to establish a connection;\n// however, the original untrimmed value will still be visible in configuration.\n```\n\nTo target a Message Transfer Agent (MTA), omit all options.\n\n## SMTPConnection#authentication\n\nassociative array of currently supported SMTP authentication mechanisms\n\n## Authors\n\neleith\nzackschuster\n\n## Testing\n\n    npm install -d\n    npm test\n\n## Contributions\n\nissues and pull requests are welcome\n","funding_links":[],"categories":["HTML","Packages","Repository","包","目录","Email","Uncategorized","Number","Network"],"sub_categories":["Email","电子邮件","邮箱","Uncategorized","邮件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleith%2Femailjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feleith%2Femailjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleith%2Femailjs/lists"}