Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mailparser

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailparser

Parse e-mails

  • 3.7.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is mailparser?

The mailparser npm package is a powerful tool for parsing email messages. It can handle various email formats and extract useful information such as headers, attachments, and the email body. This package is particularly useful for applications that need to process and analyze email content programmatically.

What are mailparser's main functionalities?

Parsing Email from a String

This feature allows you to parse an email from a raw string. The `simpleParser` function takes the raw email string and a callback function, and it returns a parsed email object containing various parts of the email such as headers, text, and attachments.

const { simpleParser } = require('mailparser');

const email = `From: sender@example.com
To: receiver@example.com
Subject: Test email

This is a test email.`;

simpleParser(email, (err, parsed) => {
  if (err) {
    console.error(err);
  } else {
    console.log(parsed);
  }
});

Parsing Email from a Stream

This feature allows you to parse an email from a stream, such as a file stream. The `simpleParser` function can take a stream as input and parse the email content, making it useful for processing large email files.

const { simpleParser } = require('mailparser');
const fs = require('fs');

const emailStream = fs.createReadStream('path/to/email.eml');

simpleParser(emailStream, (err, parsed) => {
  if (err) {
    console.error(err);
  } else {
    console.log(parsed);
  }
});

Extracting Attachments

This feature allows you to extract attachments from an email. The parsed email object contains an `attachments` array, where each attachment object includes properties like `filename` and `content`.

const { simpleParser } = require('mailparser');

const email = `From: sender@example.com
To: receiver@example.com
Subject: Test email

This is a test email with an attachment.`;

simpleParser(email, (err, parsed) => {
  if (err) {
    console.error(err);
  } else {
    parsed.attachments.forEach(attachment => {
      console.log(attachment.filename);
      console.log(attachment.content);
    });
  }
});

Other packages similar to mailparser

FAQs

Package last updated on 29 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc