UNPKG

3.68 kBMarkdownView Raw
1
2## @coolgk/email
3a javascript / typescript module
4
5`npm install @coolgk/email`
6
7a email sender wrapper class
8
9Report bugs here: [https://github.com/coolgk/node-utils/issues](https://github.com/coolgk/node-utils/issues)
10## Examples
11```javascript
12import { Email } from '@coolgk/email';
13// OR
14// const { Email } = require('@coolgk/email');
15
16const email = new Email({host: 'localhost'});
17
18email.send({
19 subject: 'hello this is email subject',
20 from: {
21 name: 'Daniel Gong',
22 email: 'daniel.k.gong@example.com'
23 },
24 to: [
25 {
26 name: 'Dan Go',
27 email: 'dan@example.com'
28 },
29 'gong@example.com'
30 ],
31 message: '<html><body><h1>test</h1>some message here <img src="cid:my-image" width="500" height="250"></body></html>',
32 attachments: [
33 {
34 path: '/tmp/test.png',
35 name: 'screenshot.png'
36 },
37 {
38 path:"/tmp/test.png",
39 headers:{"Content-ID": "<my-image>"}
40 }
41 ]
42}).then((sentMessage) => {
43 console.log(sentMessage);
44}).catch((error) => {
45 console.log(error);
46});
47
48```
49<a name="Email"></a>
50
51## Email
52**Kind**: global class
53**See**: https://www.npmjs.com/package/emailjs#emailserverconnectoptions
54
55* [Email](#Email)
56 * [new Email(options)](#new_Email_new)
57 * [.send(options, [attachments])](#Email+send) ⇒ <code>promise</code>
58
59<a name="new_Email_new"></a>
60
61### new Email(options)
62
63| Param | Type | Default | Description |
64| --- | --- | --- | --- |
65| options | <code>object</code> | | |
66| [options.user] | <code>string</code> | | username for logging into smtp |
67| [options.password] | <code>string</code> | | password for logging into smtp |
68| [options.host] | <code>string</code> | <code>&quot;&#x27;localhost&#x27;&quot;</code> | smtp host |
69| [options.port] | <code>string</code> | | smtp port (if null a standard port number will be used) |
70| [options.ssl] | <code>boolean</code> | | boolean (if true or object, ssl connection will be made) |
71| [options.tls] | <code>boolean</code> | | boolean (if true or object, starttls will be initiated) |
72| [options.domain] | <code>string</code> | | domain to greet smtp with (defaults to os.hostname) |
73| [options.authentication] | <code>Array.&lt;string&gt;</code> | | authentication methods |
74
75<a name="Email+send"></a>
76
77### email.send(options, [attachments]) ⇒ <code>promise</code>
78**Kind**: instance method of [<code>Email</code>](#Email)
79**Returns**: <code>promise</code> - - message sent
80
81| Param | Type | Description |
82| --- | --- | --- |
83| options | <code>object</code> | |
84| options.subject | <code>string</code> | email subject |
85| [options.message] | <code>string</code> | html email message |
86| options.to | <code>Array.&lt;(string\|object)&gt;</code> | to email address |
87| options.to[].name | <code>string</code> | name of the recipient |
88| options.to[].email | <code>string</code> | email address of the recipient |
89| [options.from] | <code>string</code> \| <code>object</code> | see options.to |
90| [options.cc] | <code>Array.&lt;(string\|object)&gt;</code> | see options.to |
91| [options.bcc] | <code>Array.&lt;(string\|object)&gt;</code> | see options.to |
92| [attachments] | <code>Array.&lt;object&gt;</code> | email attachments |
93| attachments.path | <code>string</code> | file path |
94| [attachments.name] | <code>string</code> | file name |
95| [attachments.type] | <code>string</code> | file mime type |
96| [attachments.method] | <code>string</code> | method to send attachment as (used by calendar invites) |
97| [attachments.headers] | <code>object</code> | attachment headers, header: value pairs, e.g. {"Content-ID":"<my-image>"} |
98