Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finish first attempt of definitions and tests.

  • Loading branch information...
commit 859b94e5e5ef2cc2d5a56e76f5d2ee1f2f1dfbb9 1 parent d3d7c7b
@vbortone vbortone authored
Showing with 143 additions and 65 deletions.
  1. +78 −28 nodemailer/nodemailer-tests.ts
  2. +65 −37 nodemailer/nodemailer.d.ts
View
106 nodemailer/nodemailer-tests.ts
@@ -1,33 +1,83 @@
-//Nodemailer test
+/// <reference path="..\node\node.d.ts" />
/// <reference path="nodemailer.d.ts" />
-var nodemailer:NodemailerStatic;
-
-// create reusable transport method (opens pool of SMTP connections)
-var smtpTransport = nodemailer.createTransport("SMTP",{
- service: "Gmail",
- auth: {
- user: "gmail.user@gmail.com",
- pass: "userpass"
- }
+
+var nodemailer: Nodemailer;
+var fs: any;
+var pathlib: any;
+
+// Create an Amazon SES transport object
+var transport:Transport = nodemailer.createTransport("SES", {
+ AWSAccessKeyID: "AWSACCESSKEY",
+ AWSSecretKey: "/AWS/SECRET",
+ ServiceUrl: "https://email.us-east-1.amazonaws.com" // optional
});
-// setup e-mail data with unicode symbols
-var mailOptions = {
- from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
- to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers
- subject: "Hello ✔", // Subject line
- text: "Hello world ✔", // plaintext body
- html: "<b>Hello world ✔</b>" // html body
-}
-
-// send mail with defined transport object
-smtpTransport.sendMail(mailOptions, function(error, response){
- if(error){
- console.log(error);
- }else{
- console.log("Message sent: " + response.message);
- }
+console.log('SES Configured');
+
+// optional DKIM signing
+
+transport.useDKIM({
+ domainName: "do-not-trust.node.ee", // signing domain
+ keySelector: "dkim", // selector name (in this case there's a dkim._domainkey.do-not-trust.node.ee TXT record set up)
+ privateKey: fs.readFileSync(pathlib.join(__dirname,"test_private.pem"))
+});
+
+
+// Message object
+var message:MailComposer = {
+
+ // sender info
+ from: 'Sender Name <sender@example.com>',
+
+ // Comma separated list of recipients
+ to: '"Receiver Name" <receiver@example.com>',
- // if you don't want to use this transport object anymore, uncomment following line
- //smtpTransport.close(); // shut down the connection pool, no more messages
+ // Subject of the message
+ subject: 'Nodemailer is unicode friendly ✔', //
+
+ // plaintext body
+ text: 'Hello to myself!',
+
+ // HTML body
+ html: '<p><b>Hello</b> to myself <img src="cid:note@node"/></p>' +
+ '<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
+
+ // An array of attachments
+ attachments: [
+
+ // String attachment
+ {
+ fileName: 'notes.txt',
+ contents: 'Some notes about this e-mail',
+ contentType: 'text/plain' // optional, would be detected from the filename
+ },
+
+ // Binary Buffer attachment
+ {
+ fileName: 'image.png',
+ contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
+ '//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
+ 'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
+
+ cid: 'note@node' // should be as unique as possible
+ },
+
+ // File Stream attachment
+ {
+ fileName: 'nyancat.gif',
+ filePath: __dirname + "/nyan.gif",
+ cid: 'nyan@node' // should be as unique as possible
+ }
+ ]
+};
+
+console.log('Sending Mail');
+
+transport.sendMail(message, function (error) {
+ if (error) {
+ console.log('Error occured');
+ console.log(error.message);
+ return;
+ }
+ console.log('Message sent successfully!');
});
View
102 nodemailer/nodemailer.d.ts
@@ -1,61 +1,89 @@
// Type definitions for Nodemailer
-// JNodemailer is an easy to use module to send e-mails with Node.JS (using SMTP or sendmail or Amazon SES) and is unicode friendly .
+// Nodemailer is an easy to use module to send e-mails with Node.JS (using SMTP or sendmail or Amazon SES) and is unicode friendly .
// Project: https://github.com/andris9/Nodemailer
// Definitions by: Vincent Bortone <https://github.com/vbortone/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
class Transport {
static transports: {
- SMTP: SMTPTransport,
- SES: SESTransport,
- SENDMAIL: SendmailTransport,
- STUB: StubTransport
+ SMTP: Transport;
+ SES: Transport;
+ SENDMAIL: Transport;
+ STUB: Transport;
};
- constructor(type: string, options?: Object);
+ constructor(type: string, options?: any);
options: Object;
- transportType: strng;
+ transportType: string;
sendMailWithTransport(emailMessage: MailComposer, callback?: (err: Error) => any): any;
useDKIM(dkim: DKIMOptions);
- close(callback?: (err: Error) => any));
+ close(callback?: (err: Error) => any);
+ sendMail(message: MailComposer, callback?: (err: Error) => any): any;
+ send_mail(message:MailComposer, callback?: (err: Error) => any): any;
}
-interface MailComposer {}
+interface NodeMailerAttachment {
+ fileName: string;
+ filePath?: string;
+ contents?: any;
+ contentType?: string;
+ cid?: string;
+}
-interface DKIMOptions{}
+interface MailComposer {
+ from: string; // sender info
+ to: string; // Comma separated list of recipients
+ subject: string; // Subject of the message
+ headers?: {};
+ text?: string; // plaintext body
+ html?: string; // HTML body
+ attachments?: NodeMailerAttachment[]; // An array of attachments
+ forceEmbeddedImages?: bool;
+}
-interface XOAuthGenerator {}
+interface DKIMOptions{
+ domainName: string; // signing domain
+ keySelector: string; // selector name (in this case there's a dkim._domainkey.do-not-trust.node.ee TXT record set up)
+ privateKey: any;
+}
-interface NodemailerTransportOptions {
- service: string;
-
+class XOAuthGenerator {
+ constructor(options: XOAuthGeneratorOptions);
+ generate(callback: () => any): string;
}
-interface NodeMailerMessageOptions {}
+interface XOAuthGeneratorOptions {
+ user: string;
+ consumerKey: string; // optional
+ consumerSecret: string; // optional
+ token: string;
+ tokenSecret: string;
+}
-// Module level exports
-interface NodemailerStatic {
- X_MAILER_NAME: string;
- X_MAILER_HOMEPAGE: string;
- createXOAuthGenerator(options: Object): XOAuthGenerator;
- createTransport(type: string, options: NodeMailerTransportOptions): Transport;
- sendMail(options: NodeMailerMessageOptions, callback?: (err: Error) => any): any;
- send_mail(options: NodeMailerMessageOptions, callback?: (err: Error) => any): any;
- stripHTML(str: string): string;
+interface XOAuth2Options {
+ user: string;
+ clientId: string;
+ clientSecret: string;
+ refreshToken: string;
+}
+
+interface NodemailerTransportOptions {
+ service?: string;
+ auth?: {
+ user?: string;
+ pass?: string;
+ XOAuthToken?: XOAuthGenerator;
+ XOAuth2?: XOAuth2Options;
+ };
+ debug?: bool;
+ AWSAccessKeyID?: string;
+ AWSSecretKey: string;
+ ServiceUrl: string;
}
interface Nodemailer {
- (options: NodeMailerMessageOptions): void;
- transport: Transport;
- options: NodeMailerMessageOptions;
- mailcomposer: MailComposer;
- generateUserAgentString(): string;
- getGlobalTransport(): Transport;
- validateSettings(callback: (err: Error) => any): void;
- sendMail(callback: () => any): void;
- generateMailObject(): void;
- setGeneralOptions(): void;
- setUserHeaders(): void;
- setModuleHeaders(): void;
- setAttachments(): void;
+ createTransport(type: string): Transport;
+ createTransport(type: string, options: NodemailerTransportOptions): Transport;
+ createTransport(type: string, path: string): Transport;
+ createXOAuthGenerator(options: XOAuthGeneratorOptions): XOAuthGenerator;
}
Please sign in to comment.
Something went wrong with that request. Please try again.