1 |
|
2 | ## @coolgk/email
|
3 | a javascript / typescript module
|
4 |
|
5 | `npm install @coolgk/email`
|
6 |
|
7 | email sender
|
8 | ## Examples
|
9 | ```javascript
|
10 | import { Email } from '@coolgk/email';
|
11 | // OR
|
12 | // const { Email } = require('@coolgk/email');
|
13 |
|
14 | const email = new Email({host: 'localhost'});
|
15 |
|
16 | email.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.stripTags] | <code>function</code> | | ./stripTags.js |
|
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>"'localhost'"</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.<string></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 |
|
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.<(string\|object)></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.<(string\|object)></code> | see options.to |
|
90 | | [options.bcc] | <code>Array.<(string\|object)></code> | see options.to |
|
91 | | [attachments] | <code>Array.<object></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 |
|