UNPKG

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