Proprietăţi MAPI
Proprietăți MAPI
Fiecare fișier MSG stochează datele ca proprietăți MAPI — perechi cheie-valoare etichetate, identificate printr-un
ID de proprietate și un cod de tip. Aspose.Email FOSS pentru .NET oferă acces direct la aceste proprietăți prin MapiMessage, MapiPropertyCollection și enumul CommonMessagePropertyId.
Citirea proprietăților
Proprietăți de conveniență
MapiMessage expune cele mai comune proprietăți ca proprietăți C# tipizate:
using Aspose.Email.Foss.Msg;
using var message = MapiMessage.FromFile("sample.msg");
Console.WriteLine(message.Subject); // string?
Console.WriteLine(message.Body); // string?
Console.WriteLine(message.HtmlBody); // string?
Console.WriteLine(message.SenderName); // string?
Console.WriteLine(message.SenderEmailAddress); // string?
Console.WriteLine(message.InternetMessageId); // string?
Console.WriteLine(message.MessageDeliveryTime); // DateTime?
Console.WriteLine(message.MessageClass); // string?Acces brut la proprietate
Pentru proprietățile care nu sunt expuse ca câmpuri de conveniență, utilizați GetPropertyValue:
// Read a string property by ID and type
var displayTo = message.GetPropertyValue(
(ushort)CommonMessagePropertyId.DisplayTo,
(ushort)PropertyTypeCode.PtypString,
decode: true);
Console.WriteLine($"Display To: {displayTo}");Iterați toate proprietățile
// List all property keys (ID + type pairs)
foreach (var key in message.IterPropertyKeys())
Console.WriteLine($"Property: 0x{key:X8}");
// Iterate full property objects
foreach (var prop in message.IterProperties())
{
Console.WriteLine($"ID=0x{prop.PropertyId:X4} " +
$"Type=0x{prop.PropertyType:X4} " +
$"Tag=0x{prop.PropertyTag:X8} " +
$"Value={prop.Value}");
}Proprietăți de scriere
Setați proprietățile unui mesaj nou
var message = MapiMessage.Create("Test", "Body");
message.SetProperty(
(ushort)CommonMessagePropertyId.SenderName,
(ushort)PropertyTypeCode.PtypString,
"Alice");
message.SetProperty(
(ushort)CommonMessagePropertyId.SenderEmailAddress,
(ushort)PropertyTypeCode.PtypString,
"alice@example.com");
message.SetProperty(
(ushort)CommonMessagePropertyId.MessageDeliveryTime,
(ushort)PropertyTypeCode.PtypTime,
new DateTime(2026, 3, 15, 10, 30, 0, DateTimeKind.Utc));Acces direct la colecție
MapiPropertyCollection furnizează Add, Set, Get și Remove:
// Access the property collection
var props = message.Properties;
// Add a property
props.Add(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32,
65001, // UTF-8
flags: 0);
// Read it back
var codepage = props.Get(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32);
Console.WriteLine($"Codepage: {codepage?.Value}");
// Remove a property
props.Remove(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32);ID-uri de proprietate comune
Enumul CommonMessagePropertyId furnizează constante denumite pentru ID-urile de proprietate MAPI utilizate frecvent:
| Property | Descriere |
|---|---|
Subject | Subiectul mesajului |
Body | Corp text simplu |
BodyHtml | Corp HTML |
SenderName | Nume afișat al expeditorului |
SenderEmailAddress | Adresă de e‑mail a expeditorului |
DisplayTo | Șir afișat al destinatarilor To |
DisplayCc | Șir afișat al destinatarilor Cc |
DisplayBcc | Șir afișat al destinatarilor Bcc |
InternetMessageId | Message-ID RFC 5322 |
MessageDeliveryTime | Marcaj temporal de livrare |
TransportMessageHeaders | Antete brute RFC 5322 |
AttachFilename | Nume fișier atașament scurt |
AttachLongFilename | Nume fișier atașament lung |
AttachMimeTag | Tip MIME al atașamentului |
AttachContentId | Content-ID al atașamentului |
Coduri tip proprietate
Enumul PropertyTypeCode mapează codurile de tip MAPI:
| Tip | Descriere |
|---|---|
PtypString | șir Unicode |
PtypString8 | șir ANSI |
PtypInteger32 | întreg pe 32 de biți |
PtypInteger64 | întreg pe 64 de biți |
PtypBoolean | Boolean |
PtypTime | DateTime (FILETIME) |
PtypBinary | tablou de octeți |
PtypGuid | GUID |
Proprietăți atașament
Fiecare MapiAttachment are, de asemenea, propria colecție Properties:
foreach (var attachment in message.Attachments)
{
Console.WriteLine($"Attachment: {attachment.Filename}");
foreach (var prop in attachment.Properties.IterProperties())
Console.WriteLine($" 0x{prop.PropertyTag:X8} = {prop.Value}");
}Vezi și
- Citirea fișierelor MSG — Încarcă și inspectează fișierele MSG
- Conversie EML — Convertește între formate
- Containere CFB — Acces la containere binare la nivel scăzut