(转)
使用aspose email创建msg文件,用outlook打开,需求要求创建草稿格式的。
To save a draft email:
Create an instance of the MailMessage class.
Set the MailMessage object's properties like subject, body, from, to and CC.
Create an instance of the MapiMessage class.
Load a MailMessage instance in the MapiMessage object using the MapiMessage class' fromMailMessage() method.
Set the message flags using the MapiMessage class' setMessageFlags() method.
Save the message to disk in Outlook format using the MapiMessage class' save() method.
public static void main(String[] args)
{
// Declare a string variable to store the path to disk location
String strBaseFolder = "D:\\Data\\Aspose\\resources\\";
// Create a new instance of MailMessage class
MailMessage message = new MailMessage();
// Set sender information
message.setFrom(new MailAddress("from@domain.com", "Sender Name", false));
// Add recipients
message.getTo().add(new MailAddress("to1@domain.com", "Recipient 1", false));
message.getTo().add(new MailAddress("to2@domain.com", "Recipient 2", false));
// Set subject of the message
message.setSubject("New message created by Aspose.Email for Java");
// Set Html body of the message
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>"
+ "<font color=blue>This line is in blue color</font>");
// Create an instance of MapiMessage and load the MailMessag instance into it
MapiMessage mapiMsg = MapiMessage.fromMailMessage(message);
// Set the MapiMessageFlags as UNSENT and FROMME
mapiMsg.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);
// Save the MapiMessage to disk
mapiMsg.save(strBaseFolder + "New-Draft.msg");
}