Skip to content

Atlantis-Software/mailx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mailx

npm version Build Status Coverage Status NSP Status Dependencies Status

mailx is a simple and complete email client library (pop, imap and smtp) for nodejs.


Write and send an Email

Message objet

the message object is used to write or read a message.

Sample: write a new message

var message = mailx.message();
message.setFrom('me', '[email protected]');
message.addTo('you', '[email protected]');
message.setSubject('hello');
message.setText('hi ! how are u?'); 
message.setHtml('hi ! how are u? <b>hugs</b>');

Transport object

the transport objet is used to send a predefined message.

Sample: sending a message

var transport = mailx.transport('smtp.example.net', 25, 'login', 'password');
transport.send(message, function(err,result) {
    console.log(result);
});

Receive Email

Store object

Sample: get all messages from server, log their subjets and delete the last one

var store = mailx.store('pop3', 'pop.example.net', 110, 'login', 'password');
store.connect(function(err) {
  if (err) {
    return console.log('connect error', err);
  }
  store.getInboxMessages(0, function(err, messages) {
    if (err) {
      return console.log('inbox error', err);
    }
    messages.forEach(function(message,index) {
      console.log(message.subject);
      if (index === messages.length - 1) {
        message.delete(function(err, data) {
          console.log('message deleted!', data);
          store.close(function(err, data) {
            console.log('store.close err:', err);
          });
        });
      }
    });
  });
});

Sample: get message by message from server and log their subjets

var store = mailx.store('imap', 'imap.example.net', 143, 'login', 'password');
store.connect(function(err) {
  if (err) {
    return console.log('err connect: ', err);
  }
  var inbox = store.getInbox(1);
  inbox.fail(function(err){
    console.log('fail get messages: ', err);
  });
  inbox.done(function(status){  
    console.log('end of inbox');
  });
  (function recursiveRcpt() {
    inbox.getNextMessage(function(err, message) {
      if (err) {
        return console.log('fail get message: ', err);
      }
      if (message === null) {
        return console.log('no more message to read');
      }
      console.log(message.subject);
      recursiveRcpt();
    });
  })();
});

About

POP,IMAP and SMTP clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •