{"library":"node-pop3","title":"POP3 Client for Node.js","description":"Node-pop3 is a JavaScript client library for the Post Office Protocol version 3 (POP3), designed for use in Node.js environments. It provides functionalities to connect to POP3 servers, authenticate users, list messages, retrieve mail content, and manage mailboxes. The library supports both Promise-based asynchronous operations for cleaner code and Node.js Streams for efficient handling of potentially large mail bodies. Version `0.11.0` is the current stable release, requiring Node.js `^20.11.0 || >= 22.0.0`. It ships with TypeScript type definitions, enhancing development experience for TypeScript users. Key differentiators include its explicit support for modern JavaScript constructs like Promises and Streams, along with a simple command-line interface (CLI) for testing. While similar libraries exist, node-pop3 aims for a direct API mirroring the POP3 protocol, rather than a high-level abstraction.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-pop3"],"cli":{"name":"pop3","version":null}},"imports":["import Pop3Command from 'node-pop3';","import Pop3Command from 'node-pop3'; /* ... */ const streamString = await Pop3Command.stream2String(retrStream);","import Pop3Command from 'node-pop3'; /* ... */ const list = Pop3Command.listify(streamString);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Pop3Command from 'node-pop3';\nimport 'dotenv/config'; // For loading environment variables\n\nasync function fetchMail() {\n  const user = process.env.POP3_USER ?? 'example@example.com';\n  const password = process.env.POP3_PASSWORD ?? 'your-password';\n  const host = process.env.POP3_HOST ?? 'pop3.example.com';\n  const port = parseInt(process.env.POP3_PORT ?? '995', 10); // Default to 995 for TLS\n  const tls = process.env.POP3_TLS === 'true';\n\n  const pop3 = new Pop3Command({\n    user,\n    password,\n    host,\n    port,\n    tls\n  });\n\n  try {\n    await pop3.connect();\n    console.log('Connected to POP3 server.');\n\n    // Authenticate (handled by constructor in common methods like RETR/UIDL)\n    // For manual command, you would do:\n    // await pop3.command('USER', user);\n    // await pop3.command('PASS', password);\n\n    const [statInfo] = await pop3.command('STAT');\n    console.log(`Mailbox status: ${statInfo}`); // e.g., '100 102400'\n\n    const list = await pop3.UIDL();\n    console.log('Messages in mailbox (UIDL):', list);\n\n    if (list.length > 0) {\n      const firstMsgNum = list[0][0];\n      console.log(`Retrieving message number ${firstMsgNum}...`);\n      const mailContent = await pop3.RETR(firstMsgNum);\n      console.log('\\n--- First Mail Content ---\\n');\n      console.log(mailContent.substring(0, 500) + '...'); // Log first 500 chars\n      console.log('\\n--------------------------\\n');\n    } else {\n      console.log('No messages in mailbox.');\n    }\n\n    const [quitInfo] = await pop3.QUIT();\n    console.log(`Disconnected: ${quitInfo}`);\n  } catch (error) {\n    console.error('An error occurred:', error.message);\n    if (error.eventName) {\n      console.error('Event Name:', error.eventName);\n    }\n    if (error.command) {\n      console.error('Command causing error:', error.command);\n    }\n  }\n}\n\nfetchMail();","lang":"typescript","description":"This quickstart demonstrates how to connect to a POP3 server, authenticate, retrieve mailbox statistics, list message UIDs, and fetch the content of the first message, finally disconnecting. It uses environment variables for credentials and showcases error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}