Additional mail properties

Hello there,

I am creating PST file using mail properties. I am assigning properties of mails to Aspose MailMessage object properties.I want to add some more properties to mail.

sent: -date and time of mail sent

received:-date and time of mail received

created:-date and time of mail created

SenderAddressType:-here i have seen like “SMTP”

MessageSize:-int e.g :-3901278

LastModificationTime:date and time of mail

TransportMessageHeader:-e.g"From:“Brian Peter<[Brian.Peter@ClarkContacts.com](mailto:Brian.Peter@ClarkContacts.com)

InternetMessageId:-[495DCFHDGB78SGS67SADNM1D@ClarkContacts.com](mailto:495DCFHDGB78SGS67SADNM1D@ClarkContacts.com)

Apart from this can we add user defined properties.?

Please reply…soon…

Hi Pooja,


Thanks for writing to Aspose.Email support team.

You can add user defined properties by using Headers property of MailMessage. Following is a sample code which adds two user defined properties named “UserDefinedProperty1” and “UserDefinedProperty2”. Initial values are also set for these newly added properties.

Please give a try to the following code and let us know your feedback.

MailMessage mail = new MailMessage("user01@gmail.com", "user02@gmail.com", “Subject”, “Body”);
mail.Save(“Mail.eml”, MailMessageSaveType.EmlFormat);
mail.Headers.Add(“UserDefinedProperty1”, “value01”);
mail.Headers.Add(“UserDefinedProperty2”, “value02”);
mail.Save(“Mail.eml”, MailMessageSaveType.EmlFormat);

Hello Sir,

Thanx for the reply…
I have one more Question can we set the property values based on their property ids.?
Please reply…

Hi Pooja,


Following are few samples which demonstrate setting the properties for MapiMessage and MailMessage. Please give it a try a let us know your feedback.

MapiMessage mapiMsg = new MapiMessage("user1@gmail.com", "user2@gmail.com", “This is subject”, “This is body”);

//Sample 01
Guid guid = Guid.NewGuid();
mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_SENDER_ADDRTYPE_W, Encoding.Unicode.GetBytes(“EX”)));

//Sample 02
MapiRecipient recipientTo = mapiMsg.Recipients[0];
MapiProperty propAddressType = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_ADDRTYPE_W, Encoding.UTF8.GetBytes(“MYFAX”));
recipientTo.SetProperty(propAddressType);
string faxAddress = “My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local”;
MapiProperty propEmailAddress = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_EMAIL_ADDRESS_W, Encoding.UTF8.GetBytes(faxAddress));
recipientTo.SetProperty(propEmailAddress);

//Sample 03
mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);

//Sample 04
mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_RTF_IN_SYNC, BitConverter.GetBytes((long)1)));

//Following are few sample for setting headers
MailMessage mail = new MailMessage("user01@gmail.com", "user02@gmail.com", “This is mail message subject”, “This is mail message body”);

//It will mark message as UNSENT
mail.Headers.Add(“X-Unsent”, “1”);

//Following will set the LastModified date time
mail.Headers[“LastModified”] = DateTime.Now.ToString();

//Following will set the From
mail.Headers[“From”] = "user3@gmail.com";