@independentsoft/msg

Outlook .msg file module

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@independentsoft/msg
1.0.23 years ago3 years agoMinified + gzip package size for @independentsoft/msg in KB

Readme

This module allows you to easy create, read, update and parse Outlook message files.

Features

- Create message, appointment, task, contact or any other Outlook item. - Read any Outlook .msg file and get all properties. - Set/Get MAPI properties. - Set/Get named properties. - Add attachments. - Read attachments. - Save attachments. - Add embedded messages. - Read embedded messages. - Save embedded messages.

Examples

Create message 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; let recipient1 = new msg.Recipient(); recipient1.addressType = "SMTP"; recipient1.displayType = msg.DisplayType.MAILUSER; recipient1.objectType = msg.ObjectType.MAILUSER; recipient1.displayName = "John@domain.com"; recipient1.emailAddress = "John@domain.com"; recipient1.recipientType = msg.RecipientType.TO; let recipient2 = new msg.Recipient(); recipient2.addressType = "SMTP"; recipient2.displayType = msg.DisplayType.MAILUSER; recipient2.objectType = msg.ObjectType.MAILUSER; recipient2.displayName = "Mary@domain.com"; recipient2.emailAddress = "Mary@domain.com"; recipient2.recipientType = msg.RecipientType.CC; let message = new msg.Message(); message.subject = "Test"; message.body = "Body text"; message.displayTo = "John Smith"; message.displayCc = "Mary Smith"; message.recipients.push(recipient1); message.recipients.push(recipient2); message.messageFlags.push(msg.MessageFlag.UNSENT); message.storeSupportMasks.push(msg.StoreSupportMask.CREATE); fs.writeFileSync("e:\\message.msg", message.toBytes()); ```
Create HTML message 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; let recipient1 = new msg.Recipient(); recipient1.addressType = "SMTP"; recipient1.displayType = msg.DisplayType.MAILUSER; recipient1.objectType = msg.ObjectType.MAILUSER; recipient1.displayName = "John@domain.com"; recipient1.emailAddress = "John@domain.com"; recipient1.recipientType = msg.RecipientType.TO; let recipient2 = new msg.Recipient(); recipient2.addressType = "SMTP"; recipient2.displayType = msg.DisplayType.MAILUSER; recipient2.objectType = msg.ObjectType.MAILUSER; recipient2.displayName = "Mary@domain.com"; recipient2.emailAddress = "Mary@domain.com"; recipient2.recipientType = msg.RecipientType.CC; const htmlBody = "Hello World bold html text" const htmlBodyWithRtf = "{\\rtf1\\ansi\\ansicpg1252\\fromhtml1 \\htmlrtf0 " + htmlBody + "}" const rtfBody = new TextEncoder().encode(htmlBodyWithRtf) let message = new msg.Message(); message.subject = "Test"; message.body = "Body text"; message.displayTo = "John Smith"; message.displayCc = "Mary Smith"; message.recipients.push(recipient1); message.recipients.push(recipient2); message.bodyTtmlText = htmlBody message.bodyRtf = rtfBody message.messageFlags.push(msg.MessageFlag.UNSENT); message.storeSupportMasks.push(msg.StoreSupportMask.CREATE); fs.writeFileSync("e:\\message.msg", message.toBytes()); ```
Read message 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; const buffer = fs.readFileSync('e:\\unicode.msg'); const message = new msg.Message(buffer) console.log("Subject: " + message.subject); console.log("Sender name: " + message.senderName); console.log("Sender email address: " + message.senderEmailAddress); console.log("Received by name: " + message.receivedByName); console.log("Received by email address: " + message.receivedByEmailAddress); console.log("Sent time: " + message.clientSubmitTime); console.log("Received time: " + message.messageDeliveryTime); console.log("Display to: " + message.displayTo); console.log("Display cc: " + message.displayCc); console.log("Body: " + message.body); ```
Add attachment 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; const buffer = fs.readFileSync("e:\\test.pdf"); let attachment = new msg.Attachment(buffer); attachment.fileName = "test.pdf"; attachment.displayName = "test.pdf"; let message = new msg.Message(); message.subject = "Test"; message.body = "Body text"; message.messageFlags.push(msg.MessageFlag.UNSENT); message.storeSupportMasks.push(msg.StoreSupportMask.CREATE); message.attachments.push(attachment) fs.writeFileSync("e:\\message.msg", message.toBytes()); ```
Get attachments 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; const buffer = fs.readFileSync("e:\\message.msg"); const message = new msg.Message(buffer); for(let i=0; i < message.attachments.length; i++) {
const attachment = message.attachments[i];
fs.writeFileSync("e:\\temp\\" + attachment.longFileName, attachment.toBytes());
} ```
Create appointment 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; let appointment = new msg.Message() appointment.messageClass = "IPM.Appointment"; appointment.subject = "Test"; appointment.body = "Body text"; appointment.location = "My Office"; appointment.appointmentStartTime = new Date(2020,11,10,8,0,0); appointment.appointmentEndTime = new Date(2020,11,10,10,0,0); fs.writeFileSync("e:\\appointment.msg", appointment.toBytes()); ```
Create contact 
```javascript import as msg from './independentsoft/msg.js'; import as fs from 'fs'; let contact = new msg.Message() contact.messageClass = "IPM.Contact"; contact.subject = "John Smith"; contact.displayNamePrefix = "Mr."; contact.displayName = "John Smith"; contact.givenName = "John"; contact.surname = "Smith"; contact.companyName = "Independentsoft"; contact.email1Address = "john@independentsoft.com"; contact.email1DisplayAs = "John"; contact.email1DisplayName = "John"; contact.email1Type = "SMTP"; contact.businessAddressCity = "NY"; contact.businessAddressStreet = "First Street"; contact.businessAddressCountry = "USA"; contact.businessAddress = "First Street, NY, USA"; contact.businessPhone = "555-666-777"; fs.writeFileSync("e:\\contact.msg", contact.toBytes()); ```