We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting Transport Headers

I need to know the correct method for being able to set the transport headers directly from the MapiMessage object.

As near as I can tell there are 4 different ways to set the transport headers. One is by using the collection, and three by setting the Mapi Property directly. I have found only one method of setting the Mapi Property directly that works. I would like to know why that is, and/or if I’m doing something wrong when calling the other methods.

I know setting mapi properties directly have worked in past versions and rely heavily on the “setStringPropertyValue” method which is why I’m confused as to why it now doesn’t seem to be working.

I have attached some sample code which should reproduce the issues I’m seeing.

Specifically I need to know

  • which methods I can safely use to set Strings
  • how should I set those string properties when I may have PT_UNICODE or PT_STRING8 tags
  • if I use the header collection, am I guaranteed that the order I add the headers will be the order of the headers when serialized to a string
Thanks,
//C

Hi Christopher,


Thank you for writing to Aspose support team.

I have also observed these issues and logged under Id: EMAILJAVA-34251 for further investigation by the product team. Following issues are mentioned:

1. MapiMessage.SetProperty(prop) with single argument sets garbage value in the property.

2. MapiMessage.SetStringPropertyValue() sets null value.

You can set properties as you have done in your code and issue will be analyzed by the product team in this regard.

Regarding information about order of the headers in the serialized string is requested by the product team and you will be notified once any update is received in this regard.


Hi Christopher,


We have investigated the issue and observed that there is no bug in Aspose.Email for Java while setting the properties. Following are the details:

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:gray”>//The MailMessage default
constructor create message in Unicode format:

// the message object is in Unicode format

<span style=“font-size: 9pt; font-family: “Courier New”;”>MapiMessage copyWorks1 = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>MapiMessage();



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Thus, the correct creation of property must be
following:

// The property tag must be MapiPropertyTag.PR_TRANSPORT_MESSAGE_HEADERS_W

// The property data must be in Unicode format

<span style=“font-size: 9pt; font-family: “Courier New”;”>MapiProperty prop = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>MapiProperty(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_TRANSPORT_MESSAGE_HEADERS_W
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“To:
cviaggi@actiance.com
<span style=“font-size: 9pt; font-family: “Courier New”;”>.getBytes(Charset.forName(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“UTF-8”
<span style=“font-size: 9pt; font-family: “Courier New”;”>)));



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Also, we must specify a correct tag to get
Unicode property value :

// The property tag must be MapiPropertyTag.PR_TRANSPORT_MESSAGE_HEADERS_W

<span style=“font-size: 9pt; font-family: “Courier New”;”>System.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>out
<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(copyWorks1.tryGetPropertyString(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_TRANSPORT_MESSAGE_HEADERS_W
<span style=“font-size: 9pt; font-family: “Courier New”;”>));





<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Note, the SetProperty() method adds a new
property if it is missing

// This method adds a new property if it is missing

<span style=“font-size: 9pt; font-family: “Courier New”;”>copyDoesntWork1.SetProperty(prop);





<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Note, SetStringPropertyValue() doesn’t add a
property, it just sets the value if property is present

// This method doesn’t a property, it just sets the value if property is
present

<span style=“font-size: 9pt; font-family: “Courier New”;”>copyDoesntWork2.SetStringPropertyValue(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_TRANSPORT_MESSAGE_HEADERS_W
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“To:
cviaggi@actiance.com
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

Kashif,

Thank you for responding.

In regards to this call and your comment:
<span style=“font-size: 9pt; font-family: “Courier New”;”>copyDoesntWork2.SetStringPropertyValue(MapiPropertyTag.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>PR_TRANSPORT_MESSAGE_HEADERS
<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“To:
cviaggi@actiance.com
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Note, SetStringPropertyValue() doesn’t add a
property, it just sets the value if property is present

// This method doesn’t a property, it just sets the value if property is
present

<span style=“font-size: 9pt; font-family: “Courier New”;”>
I have been experimenting with the API and this does not appear to be true in general for all Mapi Properties. Is your comment specific to just the transport headers or is this a generalized statement about the method itself?<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>

<span style=“font-size: 9pt; font-family: “Courier New”;”>Thanks,
//C<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>

Hi Christopher,


The behavior of the API is not specific to any particular header and it should behave the same way for all properties. Could you please share some code samples and examples that shows the different in behavior in this regard? We’ll look into it for assisting you further.

Kashif,

Attached is sample code which uses the setStringPropertyValue method and will create the mapi property when it doesn’t exist.

//C

Hi Christopher,

I have tried to compile the code by trying different versions of Apache Commons Lang but could not succeed. All the references could not be resolved using one version of this library.

Is it possible to send us a complete message which can be used for setting the property directly instead of creating the message here? It will be helpful to analyze the issue quickly and provide assistance accordingly.



I am using commons-lang-2.6.jar
I don’t have the complete message, I only have it in the form that is given to me after it is processed by our Journal end-point product.

//C

Hi Christopher,


Thank you for sharing information. We’re currently working over this query and will soon update you here with our findings.