mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
- add typedef for sendmail package
This commit is contained in:
parent
e618f3e1ef
commit
a07c515fbd
70
types/sendmail/index.d.ts
vendored
Normal file
70
types/sendmail/index.d.ts
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
// Type definitions for sendmail 1.4
|
||||
// Project: https://github.com/guileen/node-sendmail
|
||||
// Definitions by: My Self <https://github.com/me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/*~ If this module is a UMD module that exposes a global variable 'myLib' when
|
||||
*~ loaded outside a module loader environment, declare that global here.
|
||||
*~ Otherwise, delete this declaration.
|
||||
*/
|
||||
declare namespace sendMailConstructor {
|
||||
export interface IOptions {
|
||||
logger?: {
|
||||
debug?: () => void;
|
||||
info?: () => void;
|
||||
warn?: () => void;
|
||||
error?: () => void;
|
||||
};
|
||||
silent?: boolean;
|
||||
/** Default: False */
|
||||
dkim?:
|
||||
| boolean
|
||||
| {
|
||||
privateKey: string;
|
||||
keySelector: string;
|
||||
};
|
||||
/** Default: False */
|
||||
devPort?: number | boolean;
|
||||
/** Default: localhost */
|
||||
devHost?: string;
|
||||
/** Default: 25 */
|
||||
smtpPort?: number;
|
||||
/** Default: -1 - extra smtp host after resolveMX */
|
||||
smtpHost?: string | number;
|
||||
}
|
||||
|
||||
export interface IMailInput {
|
||||
from: string;
|
||||
to: string;
|
||||
cc?: string;
|
||||
bcc?: string;
|
||||
replyTo?: string;
|
||||
returnTo?: string;
|
||||
subject: string;
|
||||
type?: string;
|
||||
charset?: string;
|
||||
encoding?: string;
|
||||
id?: string;
|
||||
headers?: object;
|
||||
content?: string;
|
||||
html?: string;
|
||||
attachments?: {
|
||||
type: string;
|
||||
filename: string;
|
||||
content: any;
|
||||
}[];
|
||||
}
|
||||
}
|
||||
|
||||
type CallbackFn = (err: Error, domain: string) => void;
|
||||
|
||||
type SendMailFn = (
|
||||
mail: sendMailConstructor.IMailInput,
|
||||
callback: CallbackFn
|
||||
) => void;
|
||||
|
||||
declare function sendMailConstructor(
|
||||
options: sendMailConstructor.IOptions
|
||||
): SendMailFn;
|
||||
|
||||
export = sendMailConstructor;
|
||||
24
types/sendmail/sendmail-tests.ts
Normal file
24
types/sendmail/sendmail-tests.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import sendmail = require("sendmail");
|
||||
|
||||
const emailSender = sendmail({
|
||||
silent: false
|
||||
});
|
||||
|
||||
const sendEmail = (options: sendmail.IMailInput): Promise<boolean> =>
|
||||
new Promise((resolve, reject) => {
|
||||
emailSender(options, (err, reply) => {
|
||||
// if error happened or returned code is now started with 2**
|
||||
if (err || !reply.startsWith("2")) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
sendEmail({
|
||||
from: "Test Mail <noreply@mydomain.com>",
|
||||
to: "test@mydomain.com",
|
||||
subject: "First Test",
|
||||
html: "This is a Test message!"
|
||||
});
|
||||
22
types/sendmail/tsconfig.json
Normal file
22
types/sendmail/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"sendmail-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/sendmail/tslint.json
Normal file
1
types/sendmail/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user