From a66fe341694a8a98e685a60f34c773b998baae22 Mon Sep 17 00:00:00 2001 From: anchann Date: Sun, 5 May 2013 10:41:51 +0900 Subject: [PATCH] Nodemailer: type definitions for the SMPT-specific options As documented here: https://github.com/andris9/nodemailer#setting-up-smtp Added examples from the above source as tests. The original definition of NodemailerTransportOptions looks questionable with its AWS-specific fields, but leaving it alone for now since I'm new to nodemailer. Once typescript 0.9 is rolled out with its string parameter matcher, that should be used for specifying the type of options of the second parameter when the first one has value "SMTP". --- nodemailer/nodemailer-tests.ts | 24 +++++++++++++++++++++++- nodemailer/nodemailer.d.ts | 30 +++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/nodemailer/nodemailer-tests.ts b/nodemailer/nodemailer-tests.ts index d4458199c..94a955e67 100644 --- a/nodemailer/nodemailer-tests.ts +++ b/nodemailer/nodemailer-tests.ts @@ -80,4 +80,26 @@ transport.sendMail(message, function (error) { return; } console.log('Message sent successfully!'); -}); \ No newline at end of file +}); + + +// From the SMTP section of https://npmjs.org/package/nodemailer README + +var smptTransport1: Transport = nodemailer.createTransport("SMTP", { + service: "Gmail", // sets automatically host, port and connection security settings + auth: { + user: "gmail.user@gmail.com", + pass: "userpass" + } +}); + +var smtpTransport2: Transport = nodemailer.createTransport("SMTP", { + host: "smtp.gmail.com", // hostname + secureConnection: true, // use SSL + port: 465, // port for secure SMTP + auth: { + user: "gmail.user@gmail.com", + pass: "userpass" + } +}); + diff --git a/nodemailer/nodemailer.d.ts b/nodemailer/nodemailer.d.ts index 7d84ef447..681dd089b 100644 --- a/nodemailer/nodemailer.d.ts +++ b/nodemailer/nodemailer.d.ts @@ -69,21 +69,37 @@ interface XOAuth2Options { interface NodemailerTransportOptions { service?: string; - auth?: { - user?: string; - pass?: string; - XOAuthToken?: XOAuthGenerator; - XOAuth2?: XOAuth2Options; - }; + auth?: NodemailerAuthInterface; debug?: bool; AWSAccessKeyID?: string; AWSSecretKey: string; ServiceUrl: string; } +interface NodemailerAuthInterface { + user?: string; + pass?: string; + XOAuthToken?: XOAuthGenerator; + XOAuth2?: XOAuth2Options; +} + +interface NodemailerSMTPTransportOptions { + service?: string; + host?: string; + port?: number; + secureConnection?: bool; + name?: string; + auth: NodemailerAuthInterface; + ignoreTLS?: bool; + debug?: bool; + maxConnections?: number; +} + + interface Nodemailer { createTransport(type: string): Transport; createTransport(type: string, options: NodemailerTransportOptions): Transport; + createTransport(type: string, options: NodemailerSMTPTransportOptions): Transport; createTransport(type: string, path: string): Transport; createXOAuthGenerator(options: XOAuthGeneratorOptions): XOAuthGenerator; -} \ No newline at end of file +}