在这个简短的教程中,我们将学习如何使用 Java **将 MapiCalendar 添加到 PST,并借助定义明确的指令来设置环境并使用示例代码。使用简单的 API 接口,可以轻松地将 Mapi 日历插入 Java 中的 PST,该接口可用于在 Windows、macOs 或 Linux 等操作系统上运行的任何基于 Java 的应用程序中。
在 Java 中将 Mapi 日历插入 PST 的步骤
- 通过从存储库安装 Aspose.Email JAR 文件来建立应用程序开发环境
- 实例化 MapiCalendar 对象以添加约会信息
- 创建 MapiRecipientCollection 实例以添加会议与会者列表
- 使用 PersonalStorage 类实例在磁盘上生成一个空的 PST 文件
- 在 PST 文件中添加一个名为 Calendar 的文件夹
- 在 PST 存储文件夹中包含创建的约会
要将 MapiCalendar 添加到基于 PST Java 的 API,可以按照上述步骤有效利用。该过程通过使用 MapiCalendar 类的实例创建两个约会开始,然后使用 MapiRecipientCollection 类包括与会者列表。最后,创建 PST 文件并将约会添加到 PST 内新创建的日历文件夹中,然后保存到磁盘上。
使用 Java 将 MapiCalendar 添加到 PST 的代码
import com.aspose.email.FileFormatVersion; | |
import com.aspose.email.FolderInfo; | |
import com.aspose.email.License; | |
import com.aspose.email.MapiCalendar; | |
import com.aspose.email.MapiRecipientCollection; | |
import com.aspose.email.MapiRecipientType; | |
import com.aspose.email.PersonalStorage; | |
import com.aspose.email.StandardIpmFolder; | |
import java.io.File; | |
import java.util.Date; | |
public class CalenderInPST { | |
public static void main2(String[] args) throws Exception {// Exception for MSG to HTML conversion | |
String filePath= "/Users/Documents/TestData/"; | |
// Applying the API license to insert the calender in PST | |
License calenderToPSTLic = new License(); | |
calenderToPSTLic.setLicense(filePath + "Conholdate.Total.Product.Family.lic"); | |
// Create the appointment | |
MapiCalendar appointmentInfo = new MapiCalendar( | |
"Aspose-Conference room", | |
"Appointment", | |
"This is an important meeting :)", | |
new Date(2022, 10, 17, 14, 0, 0), | |
new Date(2022, 10, 17, 15, 0, 0)); | |
// Add the meeting | |
MapiRecipientCollection attendeeList = new MapiRecipientCollection(); | |
attendeeList.add("peter@gmail.com", "Peter", MapiRecipientType.MAPI_TO); | |
attendeeList.add("Szlls@dayrep.com", "Liza", MapiRecipientType.MAPI_TO); | |
MapiCalendar meetingDetails = new MapiCalendar( | |
"Dev meeting in Office Conference room", | |
"Meeting", | |
"Please confirm your availability to attend the meeting.", | |
new Date(2022, 10, 17, 14, 0, 0), | |
new Date(2022, 10, 17, 15, 0, 0), | |
"testdev@dayrep.com", | |
attendeeList | |
); | |
String PstPath = filePath + "MapiCalendarInPST_out.pst"; | |
PersonalStorage pstFile = PersonalStorage.create(PstPath, FileFormatVersion.Unicode); | |
{ | |
FolderInfo calendarFolder = pstFile.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments); | |
calendarFolder.addMapiMessageItem(appointmentInfo); | |
calendarFolder.addMapiMessageItem(meetingDetails); | |
} | |
} | |
} |
Java 中的上述代码示例使用几行代码将 Mapi 日历插入 PST。 MapiCalendar 类提供丰富的约会消息定制,包括添加普通正文内容、RTF 正文内容、HTML 正文内容、插入附件和提供以添加约会位置等等。 MapiRecipient 类允许您包含附加信息,例如任何约会消息的显示名称、收件人类型和收件人响应跟踪状态。
在本文中,我们重点介绍了如何使用基于 Java* 的 API *将 MapiCalendar 插入 PST。如果您有兴趣了解如何将电子邮件转换为 HTML,请参阅 如何使用 Java 将 Outlook 电子邮件转换为 HTML 上的文章。