We are trying to export mail into a PST. I am able to create the PST, add folders, and messages. but the attachments are not show up when viewed in Outlook. The size of the messages lets me know the attachment is there, but it is not visible. What am I doing wrong?
import com.aspose.email.*;
import java.io.File;
public class Example
{
public static void test()
{
String pstFileName = “C:\TestRun\test.pst”;
try
{
File f = new File(pstFileName);
if (f.exists()) { f.delete();}
PersonalStorage pst = PersonalStorage.create(pstFileName, 0);
FolderInfo root = pst.getRootFolder();
FolderInfo inbox = root.addSubFolder(“Inbox”);
AddMessage(inbox, “Subject 2”, “body”, “C:\TestRun\File1.txt”);
}
catch (Exception ex)
{
System.out.println(“Exception: " + ex.getMessage());
}
}
private static void AddMessage(FolderInfo folder, String subject, String Body, String attachment)
{
MailMessage m = new MailMessage("from@domain.com”, "to@domain.com", subject, Body);
if (null != attachment)
{
Attachment att = new Attachment(attachment);
m.addAttachment(att);
}
MapiMessage message = MapiMessage.fromMailMessage(m,);
message.setMessageFlags(MapiMessageFlags.MSGFLAG_READ);
folder.addMessage(message);
}
}