UNPKG

@independentsoft/msg

Version:

Outlook .msg file module

38 lines (31 loc) 1.43 kB
import * as msg from './../independentsoft/msg.js'; import * as fs from 'fs'; let recipient1 = new msg.Recipient(); recipient1.addressType = "SMTP"; recipient1.displayType = msg.DisplayType.MAIL_USER; recipient1.objectType = msg.ObjectType.MAIL_USER; 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.MAIL_USER; recipient2.objectType = msg.ObjectType.MAIL_USER; recipient2.displayName = "Mary@domain.com"; recipient2.emailAddress = "Mary@domain.com"; recipient2.recipientType = msg.RecipientType.CC; const htmlBody = "<html><body><b>Hello World bold html text</b></body></html>" 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());