I have this below code, which parses the email subject, what are the other params which i can parse through this?
const ae = require('@aspose/email');
const pst = ae.Storage.Pst.PersonalStorage.fromFile("outlook.pst");
const rootFolders = pst.rootFolder.getSubFolders();
for( folder of rootFolders) {
console.log("Folder: ", folder.displayName);
console.log("Total Items: ", folder.contentCount);
console.log("Total Unread Items: ", folder.contentUnreadCount);
console.log("----------------------");
for(msg of folder.enumerateMessages()) {
console.log(" ", msg.subject);
}
}
I need to fetch all the details of each email, say From, To, cc, Bcc, attachments, inline images etc.
Hello @MaazHussain ,
Welcome to our support forum!
To parse additional properties of emails from the PST file using the @aspose/email library, you can fetch details like From, To, CC, BCC, Attachments, and inline images using the ae.MapiMessage class.
Here’s an example of how you can extract the requested properties:
const ae = require('@aspose/email');
const pst = ae.Storage.Pst.PersonalStorage.fromFile("outlook.pst");
const rootFolders = pst.rootFolder.getSubFolders();
for (const folder of rootFolders) {
console.log("Folder: ", folder.displayName);
console.log("Total Items: ", folder.contentCount);
console.log("Total Unread Items: ", folder.contentUnreadCount);
console.log("----------------------");
for (const mapiMsg of folder.enumerateMapiMessages()) {
console.log("Subject: ", mapiMsg.subject);
// From
console.log("From: ", mapiMsg.senderEmailAddress || "No Sender");
// To Recipients
console.log("To: ");
for (const recipient of mapiMsg.recipients) {
if (recipient.recipientType === ae.Mapi.MapiRecipientType.MAPI_TO) {
console.log(" - ", recipient.emailAddress);
}
}
// CC Recipients
console.log("CC: ");
for (const recipient of mapiMsg.recipients) {
if (recipient.recipientType === ae.Mapi.MapiRecipientType.MAPI_CC) {
console.log(" - ", recipient.emailAddress);
}
}
// BCC Recipients
console.log("BCC: ");
for (const recipient of mapiMsg.recipients) {
if (recipient.recipientType === ae.Mapi.MapiRecipientType.MAPI_BCC) {
console.log(" - ", recipient.emailAddress);
}
}
// Attachments
console.log("Attachments:");
for (const attachment of mapiMsg.attachments) {
console.log(" - Name: ", attachment.displayName);
// You can save the attachment to disk if needed
//attachment.save("D:\\attach\\" + attachment.longFileName);
}
console.log("----------------------");
}
}
Thank you @margarita.samodurova , this helped a lot. I still have 3 queries if you could help me with it.
- Do we have any documentation to find what all can be accessed from the ae.MapiMessage class.
- Im also looking to parse .olm files in a similar way, can you help me out with a base setup for that as well, and if we have documentation for the same kindly share that as well.
- Will it be possible to convert this NodeJS code into a plain javascript code, or is
@aspose/email
package is inherently designed for Node.js environments (Source: Using RollUp.js)
Regards,
Maaz Hussain
Hello @MaazHussain ,
We’ll consider your requests and contact you soon.
Thanks for your patience.
Hello @MaazHussain,
-
Currently, you can use the API Reference for Aspose.Email for .NET: https://reference.aspose.com/email/net/aspose.email.mapi/mapimessage/. Please note that in the Node.js implementation, member names of the class start with lowercase.
-
For parsing .olm
files, you can use the following code snippet:
const ae = require('@aspose/email');
// Load the OLM file
const olm = ae.Storage.Olm.OlmStorage.fromFile("storage.olm");
const folders = olm.getFolders();
for (const folder of folders) {
console.log(`Folder: ${folder.name}`);
console.log(`Total Items: ${folder.messageCount}`);
console.log('----------------------');
// Enumerate messages in the folder
for (const mapiMsg of folder.enumerateMapiMessages()) {
// Process the MapiMessage here
}
}
- Due to the integration of .NET AOT and the native Node.js environment, the
@aspose/email
package is not suitable for plain JavaScript. The recommended approach is to use it in a server-side Node.js environment.
You’re welcome!
Let us know if you have any more questions or need further assistance.