HTML Body is not proper in Calendar in PST file Using Aspose.Email for Java API


Hello Kashif,
I am trying to create calendars in PST File. But i have problem with HTML body in calendar is not shown properly. Please find the sample code and output PST file that i have generated at my end.

**************Source code :- ****************
MapiCalendar f_MapiCalendarObj = new MapiCalendar(f_Location,subject,subject, startDate, endByDate); // CREATE MAPICALENDAR OBJECT

f_MapiCalendarObj.setBodyContent(p_AppointmentObj.HTMLBody,BodyContentType.Html); // ADD HTML BODY

f_FolderInfoObj.addMapiMessageItem(f_MapiCalendarObj); // ADD CELENDAR IN PST FOLDER


**Snapshort of Issue :-
green mark in the image indicate correct html body and red mark indicate wrong html body. Please see image and understand.

russian charcter.png (395.6 KB)

***********OUTPUT PST ***********
Russian Character is not (92.9 KB)


This is Source of HTML Body :-

அனைத்து கட்டாய துறைகள் சரிபார்க்கப்பட்டது மற்றும் நட்சத்திர சுட்டிக்காட்டப்படுகிறது வேண்டும் () சின்னமாக
சரிபார்ப்பு பிழை செய்திகளை சரியான இடத்தில் சரியான முறையில் காண்பிக்க வேண்டும்(tamil)
 Все обязательные поля должны быть проверены и обозначены звездочкой () символ
. Сообщения об ошибках валидации должны правильно отображаться в правильном положении(russian)

2. توثیق خرابی کے پیغامات کو صحیح پوزیشن میں مناسب طریقے سے ظاہر ہونا چاہئے
3. تمام خرابی کے پیغامات (جیسے لال رنگ کا استعمال کرتے ہوئے) اسی CSS انداز میں ظاہر ہونا چاہئے
4. جنرل تصدیق پیغامات (جیسے سبز رنگ کا استعمال کرتے ہوئے) خرابی کے پیغامات سٹائل کے علاوہ کسی اور (urdu)

2. 유효성 검사 오류 메시지가 올바른 위치에 제대로 표시해야
3. 모든 오류 메시지 (예를 들면 붉은 색을 사용) 동일한 CSS 스타일에 표시해야
4. 일반 확인 메시지 (예를 들어 녹색을 사용하여) 오류 메시지 스타일 이외의 CSS 스타일을 사용하여 표시한다
5. 도구 설명 텍스트는 의미가 있어야한다
6. 드롭 다운 필드 등의 공백 또는(korean)




We have investigated the issue by saving the html contents to a file and then setting it to the html content of calendar item. The calendar item body seems similar to that of the HTML file when loaded in MS Outlook. Following is the sample code that we have tried at our end with the latest version of the API. Please share the original message file with us for further investigation at our end.

Sample Code

private static void checkCalToPstBodyIssue() throws IOException
	MapiCalendar appointment = new MapiCalendar();
	appointment.setLocation("LAKE ARGYLE WA 6743");
	appointment.setBody("This is a very important meeting");

	Date startDate = null;
	Calendar cal = GregorianCalendar.getInstance();
	cal.set(2017, 10, 2);
	startDate = cal.getTime();

	Date endDate = null;
	cal = GregorianCalendar.getInstance();
	cal.set(2017, 10, 3);
	endDate = cal.getTime();

	appointment.setBodyContent(readFile("htmlbody.html", StandardCharsets.UTF_16), BodyContentType.Html);"html.msg", AppointmentSaveFormat.Msg);
	PersonalStorage pst = PersonalStorage.create("HtmlBody.pst", FileFormatVersion.Unicode);
	FolderInfo f_FolderInfoObj = pst.createPredefinedFolder("Cal1", StandardIpmFolder.Appointments);

static String readFile(String path, Charset encoding) 
		  throws IOException 
		  byte[] encoded = Files.readAllBytes(Paths.get(path));
		  return new String(encoded, encoding);

where htmlbody.html contains the html content you have shared above. Please try it with the latest version of the API and let us know your (1.2 KB)


This is your hardcoded logic. Some times i got UTF-16 mails or some time i got UTF-8 mails. At that case it get fails.
Please give me proper way.



Aspose.Email for Java does not contain any feature which can be used to detect the stream encoding. If we google we find something as follows:

Detecting encodings is a very hard problem, and for some encodings, the only way to know one of them is right is through contextual analysis (which is a very non-trivial task). If you know exactly which encodings you need to support (e.g. UTF-16, UTF-8, ISO-8859-1), it may become easier, but it depends on what those encodings are

You may please use some external library to detect the encoding. Please feel free to write us back if you have any other query related to Aspose.Email for Java.