forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodemailer.d.ts
234 lines (212 loc) · 6.9 KB
/
nodemailer.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Type definitions for Nodemailer 1.3.2
// Project: https://github.com/andris9/Nodemailer
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../bluebird/bluebird-2.0.d.ts" />
/// <reference path="../node/node.d.ts" />
/// <reference path="../nodemailer-direct-transport/nodemailer-direct-transport.d.ts" />
/// <reference path="../nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts" />
declare module "nodemailer" {
import directTransport = require("nodemailer-direct-transport");
import smtpTransport = require("nodemailer-smtp-transport");
import * as Promise from 'bluebird';
export type Transport = nodemailer.Transport;
export type SendMailOptions = nodemailer.SendMailOptions;
export type SentMessageInfo = nodemailer.SentMessageInfo;
/**
* Transporter plugin
*/
export interface Plugin {
(mail: SendMailOptions, callback?: (error: Error, info: SentMessageInfo) => void): void;
}
/**
* This is what you use to send mail
*/
export interface Transporter {
/**
* Send a mail with callback
*/
sendMail(mail: SendMailOptions, callback: (error: Error, info: SentMessageInfo) => void): void;
/**
* Send a mail
* return Promise
*/
sendMail(mail: SendMailOptions): Promise<SentMessageInfo>;
/**
* Send mail using a template.
*/
templateSender(template?: any, defaults?: any): (mailData: any, context: any) => Promise<SentMessageInfo>;
/**
* Send mail using a template with a callback.
*/
templateSender(template?: any, defaults?: any, callback?: (error: Error, info: SentMessageInfo) => void): void;
/**
* Attach a plugin. 'compile' and 'stream' plugins can be attached with use(plugin) method
*
* @param step is a string, either 'compile' or 'stream' thatd defines when the plugin should be hooked
* @param pluginFunc is a function that takes two arguments: the mail object and a callback function
*/
use(step: string, plugin: Plugin): void;
/**
* Verifies connection with server
*/
verify(callback: (error: Error, success?: boolean) => void): void;
/**
* Verifies connection with server
*/
verify(): Promise<void>;
/**
* Close all connections
*/
close?(): void;
}
/**
* Create a direct transporter
*/
export function createTransport(options?: directTransport.DirectOptions, defaults?: Object): Transporter;
/**
* Create an SMTP transporter
*/
export function createTransport(options?: smtpTransport.SmtpOptions, defaults?: Object): Transporter;
/**
* Create a transporter from a given implementation
*/
export function createTransport(transport: Transport, defaults?: Object): Transporter;
}
declare namespace nodemailer {
export interface AttachmentObject {
/**
* filename to be reported as the name of the attached file, use of unicode is allowed
*/
filename?: string;
/**
* optional content id for using inline images in HTML message source
*/
cid?: string;
/**
* Pathname or URL to use streaming
*/
path?: string;
/**
* String, Buffer or a Stream contents for the attachment
*/
content: string|Buffer|NodeJS.ReadableStream;
/**
* If set and content is string, then encodes the content to a Buffer using the specified encoding. Example values: base64, hex, 'binary' etc. Useful if you want to use binary attachments in a JSON formatted e-mail object.
*/
encoding?: string;
/**
* optional content type for the attachment, if not set will be derived from the filename property
*/
contentType?: string;
/**
* optional content disposition type for the attachment, defaults to 'attachment'
*/
contentDisposition?: string;
}
export interface SendMailOptions {
/**
* The e-mail address of the sender. All e-mail addresses can be plain '[email protected]' or formatted 'Sender Name <[email protected]>', see here for details
*/
from?: string;
/**
* An e-mail address that will appear on the Sender: field
*/
sender?: string;
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the To: field
*/
to?: string|string[];
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field
*/
cc?: string|string[];
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field
*/
bcc?: string|string[];
/**
* An e-mail address that will appear on the Reply-To: field
*/
replyTo?: string;
/**
* The message-id this message is replying
*/
inReplyTo?: string;
/**
* Message-id list (an array or space separated string)
*/
references?: string|string[];
/**
* The subject of the e-mail
*/
subject?: string;
/**
* The plaintext version of the message as an Unicode string, Buffer, Stream or an object {path: '...'}
*/
text?: string|Buffer|NodeJS.ReadableStream|AttachmentObject;
/**
* The HTML version of the message as an Unicode string, Buffer, Stream or an object {path: '...'}
*/
html?: string|Buffer|NodeJS.ReadableStream|AttachmentObject;
/**
* An object or array of additional header fields (e.g. {"X-Key-Name": "key value"} or [{key: "X-Key-Name", value: "val1"}, {key: "X-Key-Name", value: "val2"}])
*/
headers?: any;
/**
* An array of attachment objects (see below for details)
*/
attachments?: AttachmentObject[];
/**
* An array of alternative text contents (in addition to text and html parts) (see below for details)
*/
alternatives?: AttachmentObject[];
/**
* optional Message-Id value, random value will be generated if not set
*/
messageId?: string;
/**
* optional Date value, current UTC string will be used if not set
*/
date?: Date;
/**
* optional transfer encoding for the textual parts (defaults to 'quoted-printable')
*/
encoding?: string;
}
export interface SentMessageInfo {
/**
* most transports should return the final Message-Id value used with this property
*/
messageId: string;
/**
* includes the envelope object for the message
*/
envelope: any;
/**
* is an array returned by SMTP transports (includes recipient addresses that were accepted by the server)
*/
accepted: string[];
/**
* is an array returned by SMTP transports (includes recipient addresses that were rejected by the server)
*/
rejected: string[];
/**
* is an array returned by Direct SMTP transport. Includes recipient addresses that were temporarily rejected together with the server response
*/
pending?: string[];
/**
* is a string returned by SMTP transports and includes the last SMTP response from the server
*/
response: string;
}
/**
* This is what you implement to create a new transporter yourself
*/
export interface Transport {
name: string;
version: string;
send(mail: SendMailOptions, callback?: (error: Error, info: SentMessageInfo) => void): void;
close(): void;
}
}