Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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();
}
});
});
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();
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()
})
})
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);
};
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 () {
const success = (rawEmail) => {
const mailparser = new MailParser();
mailparser.on('end', (parsedEmail) => {
callback(null, parsedEmail);
});
mailparser.write(rawEmail);
mailparser.end();
};
const error = (error) => {
f.on('message', function(msg, seqno) {
var mailParser = new MailParser();
mailParser.on('end', processMailObject);
msg.on('body', function(stream, info) {
stream.on('data', function(chunk) {
mailParser.write(chunk);
});
});
msg.once('end', function() {
mailParser.end();
});
});
function (req) {
var mailparser = new MailParser();
mailparser.on('end', function (email) {
email.attachments = (email.attachments||[]).map(function(attachment){
attachment.content = attachment.content.toString('base64');
return attachment;
});
storage.push(email);
});
req.pipe(mailparser);
req.accept();
}).listen(port);
function parseMailHeaders (headers, callback) {
var mailparser = new MailParser();
mailparser.once('end', callback);
mailparser.write(headers);
mailparser.end();
}