{"library":"nodemailer-build-attachment","title":"Nodemailer Attachment Builder","description":"nodemailer-build-attachment is a utility package designed to simplify the creation and streaming of email attachments for use with Nodemailer. It builds attachment content, allowing input from various sources like file streams, and processes it into a format suitable for email transmission, typically a `base64` encoded string. The package is currently at version 3.0.0. Its release cadence is not explicitly stated in the provided documentation, and the latest major release dates back approximately five years. A key differentiator is its specialized focus on processing stream content for attachments, building upon the `buildmail` library for robust email part construction, rather than being a general email sending library itself.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install nodemailer-build-attachment"],"cli":null},"imports":["const BuildAttachment = require('nodemailer-build-attachment');","import BuildAttachment from 'nodemailer-build-attachment';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const BuildAttachment = require('nodemailer-build-attachment');\nconst fs = require('fs');\nconst path = require('path');\n\n// Create a dummy file for demonstration purposes\nconst filePath = path.join(__dirname, 'temp-attachment.txt');\nfs.writeFileSync(filePath, 'This is the content of the attachment file generated by the example.');\n\nconst stream = fs.createReadStream(filePath);\nconst options = {\n    filename: 'document.txt', // Recommended: specify filename\n    contentType: 'text/plain', // Recommended: specify content type\n    contentTransferEncoding: 'base64'\n};\n\nnew BuildAttachment(options).setContent(stream).build((err, attachment) => {\n    if (err) {\n        console.error('Error building attachment:', err);\n        return;\n    }\n    console.log('Attachment built successfully.');\n    console.log('Attachment content (base64):', attachment.content.toString().substring(0, 50) + '...'); // Truncate for display\n    console.log('Attachment headers:', attachment.headers);\n\n    // In a real Nodemailer scenario, 'attachment' would be used like this:\n    // const nodemailer = require('nodemailer');\n    // const transporter = nodemailer.createTransport(...);\n    // transporter.sendMail({\n    //     from: 'sender@example.com',\n    //     to: 'recipient@example.com',\n    //     subject: 'Test Attachment',\n    //     attachments: [{\n    //         filename: attachment.filename || options.filename,\n    //         content: attachment.content,\n    //         contentType: attachment.contentType\n    //         // ... other properties from attachment.headers as needed\n    //     }]\n    // }).then(...);\n\n    // Clean up the dummy file\n    fs.unlinkSync(filePath);\n});","lang":"javascript","description":"Demonstrates how to initialize the BuildAttachment class, set its content from a file stream, and build a base64 encoded attachment object ready for use with Nodemailer. It also shows basic error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}