diff --git a/types/sendmail/index.d.ts b/types/sendmail/index.d.ts new file mode 100644 index 0000000000..191c0514fb --- /dev/null +++ b/types/sendmail/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for sendmail 1.4 +// Project: https://github.com/guileen/node-sendmail +// Definitions by: My Self +// 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; diff --git a/types/sendmail/sendmail-tests.ts b/types/sendmail/sendmail-tests.ts new file mode 100644 index 0000000000..f57c3b00d9 --- /dev/null +++ b/types/sendmail/sendmail-tests.ts @@ -0,0 +1,24 @@ +import sendmail = require("sendmail"); + +const emailSender = sendmail({ + silent: false +}); + +const sendEmail = (options: sendmail.IMailInput): Promise => + 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 ", + to: "test@mydomain.com", + subject: "First Test", + html: "This is a Test message!" +}); diff --git a/types/sendmail/tsconfig.json b/types/sendmail/tsconfig.json new file mode 100644 index 0000000000..c4cf4b7613 --- /dev/null +++ b/types/sendmail/tsconfig.json @@ -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" + ] +} diff --git a/types/sendmail/tslint.json b/types/sendmail/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sendmail/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }