How to use mailparser - 10 common examples

To help you get started, we’ve selected a few mailparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nomospace / nodemail / demo / mailparser / demo2 / mail-parser.js View on Github external
var MailParser = require("mailparser").MailParser,
    mailparser = new MailParser();

var email = "From: 'Sender Name' \r\n"+
            "To: 'Receiver Name' \r\n"+
            "Subject: Hello world!\r\n"+
            "\r\n"+
            "How are you today?";

// setup an event listener when the parsing finishes
mailparser.on("end", function(mail_object){
    console.log("From:", mail_object.from); //[{address:'sender@example.com',name:'Sender Name'}]
    console.log("Subject:", mail_object.subject); // Hello world!
    console.log("Text body:", mail_object.text); // How are you today?
});

// send the email source to the parser
mailparser.write(email);
github oaeproject / Hilary / node_modules / oae-email / lib / api.js View on Github external
emailTransport.sendMail(emailInfo, function(err, info) {
                    if (err) {
                        log().error({'err': err, 'to': emailInfo.to, 'subject': emailInfo.subject}, 'Error sending email to recipient');
                        return callback(err);
                    }
                    // If we're debugging we log the mail that would have been sent
                    if (debug) {
                        log().info({'to': emailInfo.to, 'subject': emailInfo.subject}, 'Sending email');

                        // Parse the email so our unit tests can inspect the result
                        var mailparser = new MailParser();
                        mailparser.on('end', function(email_object){
                            EmailAPI.emit('debugSent', email_object);
                            return callback();
                        });
                        mailparser.write(info.response);
                        mailparser.end();
                    } else {
                        return callback();
                    }
                });
            });
github RedMail / RedMail / ts.js View on Github external
var smtp = require('smtp-protocol'); 
import { MailParser } from 'mailparser'
var mailparser = new MailParser();
var concat = require('concat-stream');
var data = ''

mailparser.on("end", function(mail_object){
  // console.log(mail_object)
})

var server = smtp.createServer(function(req) {
  req.on('greeting', function(to, ack) {   
    console.log(to)  // 这里是刚才的 helo 之后的回调  
    ack.accept();
  });

  req.on('from', function(to, ack) {  
    console.log(to) // 输入过发信人后的回调 mail from:
    ack.accept();
github RocketChat / Rocket.Chat / app / lib / server / lib / interceptDirectReplyEmails.js View on Github external
this.pop3.on('retr', Meteor.bindEnvironment((status, msgnumber, data) => {
			if (status) {
				// parse raw email data to  JSON object
				simpleParser(data, Meteor.bindEnvironment((err, mail) => {
					this.initialProcess(mail);
				}));

				this.currentMsgCount += 1;

				// delete email
				this.pop3.dele(msgnumber);
			} else {
				console.log('Cannot Retrieve Message ....');
			}
		}));
github mozilla-b2g / gaia / apps / email / js / ext / imap.js View on Github external
// only one connection will see it.  Accordingly, there's no need to
      // trouble consumers with it.
      fetchData.flags = result[i+1].filter(isNotEmptyOrRecent);
      // simplify comparison for downstream logic by sorting.
      fetchData.flags.sort();
    }
    // MODSEQ (####)
    else if (result[i] === 'MODSEQ')
      fetchData.modseq = result[i+1].slice(1, -1);
    else if (result[i] === 'BODYSTRUCTURE')
      fetchData.structure = parseBodyStructure(result[i+1]);
    else if (typeof result[i] === 'string') // simple extensions
      fetchData[result[i].toLowerCase()] = result[i+1];
    else if (Array.isArray(result[i]) && typeof result[i][0] === 'string' &&
             result[i][0].indexOf('HEADER') === 0 && literalData) {
      var mparser = new mailparser.MailParser();
      mparser._remainder = literalData;
      // invoke mailparser's logic in a fully synchronous fashion
      process.immediate = true;
      mparser._process(true);
      process.immediate = false;
      /*
      var headers = literalData.split(/\r\n(?=[\w])/), header;
      fetchData.headers = {};
      for (var j=0,len2=headers.length; j
github mozilla-b2g / gaia / apps / email / js / ext / mailapi / imap / probe.js View on Github external
// only one connection will see it.  Accordingly, there's no need to
      // trouble consumers with it.
      fetchData.flags = result[i+1].filter(isNotEmptyOrRecent);
      // simplify comparison for downstream logic by sorting.
      fetchData.flags.sort();
    }
    // MODSEQ (####)
    else if (result[i] === 'MODSEQ')
      fetchData.modseq = result[i+1].slice(1, -1);
    else if (result[i] === 'BODYSTRUCTURE')
      fetchData.structure = parseBodyStructure(result[i+1]);
    else if (typeof result[i] === 'string') // simple extensions
      fetchData[result[i].toLowerCase()] = result[i+1];
    else if (Array.isArray(result[i]) && typeof result[i][0] === 'string' &&
             result[i][0].indexOf('HEADER') === 0 && literalData) {
      var mparser = new mailparser.MailParser();
      mparser._remainder = literalData;
      // invoke mailparser's logic in a fully synchronous fashion
      process.immediate = true;
      mparser._process(true);
      process.immediate = false;
      /*
      var headers = literalData.split(/\r\n(?=[\w])/), header;
      fetchData.headers = {};
      for (var j=0,len2=headers.length; j
github mozilla-b2g / gaia-email-libs-and-more / data / lib / imap.js View on Github external
// only one connection will see it.  Accordingly, there's no need to
      // trouble consumers with it.
      fetchData.flags = result[i+1].filter(isNotEmptyOrRecent);
      // simplify comparison for downstream logic by sorting.
      fetchData.flags.sort();
    }
    // MODSEQ (####)
    else if (result[i] === 'MODSEQ')
      fetchData.modseq = result[i+1].slice(1, -1);
    else if (result[i] === 'BODYSTRUCTURE')
      fetchData.structure = parseBodyStructure(result[i+1]);
    else if (typeof result[i] === 'string') // simple extensions
      fetchData[result[i].toLowerCase()] = result[i+1];
    else if (Array.isArray(result[i]) && typeof result[i][0] === 'string' &&
             result[i][0].indexOf('HEADER') === 0 && literalData) {
      var mparser = new mailparser.MailParser();
      mparser._remainder = literalData;
      // invoke mailparser's logic in a fully synchronous fashion
      process.immediate = true;
      mparser._process(true);
      process.immediate = false;
      /*
      var headers = literalData.split(/\r\n(?=[\w])/), header;
      fetchData.headers = {};
      for (var j=0,len2=headers.length; j
github adonisjs / adonis-mail / test / unit / log.spec.js View on Github external
co(function * () {
      const message = new Message()
      message.to('virk@foo.com')
      message.header([{key: 'x-id', value: 2}, {key: 'x-user', value: 'doe'}])
      message.from('virk@bar.com')
      message.subject('Hello world')
      message.html('<h2>Hello world</h2>')
      message.text('Hello world')
      const log = new Log(Config)
      yield log.send(message.data)
      const mailparser = new MailParser()

      const emailLogs = yield fs.readFile(Config.get().toPath, 'utf8')
      const email = emailLogs.split(/-\s?Email Start\s?-/gi).pop().replace(/-\s?EMAIL END\s?-/i, '').trim()

      mailparser.on('end', function (mailObject) {
        expect(mailObject.headers['x-id']).to.equal('2')
        expect(mailObject.headers['x-user']).to.equal('doe')
        done()
      })

      mailparser.write(email)
      mailparser.end()
    })
  })
github sawyerh / highlight-utils / packages / highlights-lambda / debugging.js View on Github external
const _import = function _import() {
  const mailparser = new MailParser();
  mailparser.on("end", function(mail) {
    const plaintext = new Plaintext(mail);

    console.log("Parseable: ", plaintext.parseable());
    console.log(plaintext.parse(mail));
  });
  fs.createReadStream(path.resolve("exports/text-email")).pipe(mailparser);
};
github ronny3050 / email-mirror / notifier.js View on Github external
fetch.on('message', function (msg) {
            var mp = new MailParser();
            var s = null;
            mp.once('end', function (mail) {
                self.emit('mail', mail, s);
                dbg(s);
            });
            msg.once('body', function (stream, info) {
                stream.pipe(mp);
                s = info.seqno;
            });
        });
        fetch.once('end', function () {

mailparser

Parse e-mails

MIT
Latest version published 24 days ago

Package Health Score

77 / 100
Full package analysis

Similar packages