Skip to content

Commit 02ff270

Browse files
Restructured all examples into single project
1 parent efe4d0d commit 02ff270

File tree

28 files changed

+593
-3
lines changed

28 files changed

+593
-3
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ obj/
44
classes/
55
generated/
66
bin/
7-
* Out*
8-
* out*
97
*.ldb
108
_ReSharper*/
119
*.iws
@@ -22,7 +20,6 @@ build.xml
2220
Thumbs.db
2321
manifest.mf
2422
Out/
25-
Out*/
2623
*.lic
2724
Data/*Out*
2825
.idea/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.msg;
10+
11+
import com.aspose.email.*;
12+
import com.aspose.email.examples.Utils;
13+
14+
public class AccessingOutlookMAPIProperties
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(AccessingOutlookMAPIProperties.class);
20+
21+
try
22+
{
23+
//Instantiate an MSG file to load an MSG file from disk
24+
MapiMessage outlookMessageFile=MapiMessage.fromFile(dataDir + "message.msg");
25+
26+
//get the MapiProperties collection
27+
MapiPropertyCollection coll = outlookMessageFile.getProperties();
28+
29+
//Access the MapiPropertyTag.PR_SUBJECT property
30+
MapiProperty prop = (MapiProperty)coll.get_Item((Object)MapiPropertyTag.PR_SUBJECT);
31+
32+
//if the MapiProperty is not found, check the MapiProperty.PR_SUBJECT_W
33+
//which is a unicode peer of MapiPropertyTag.PR_SUBJECT
34+
if (prop == null)
35+
{
36+
prop = (MapiProperty)coll.get_Item(MapiPropertyTag.PR_SUBJECT_W);
37+
}
38+
39+
// if it cannot be found
40+
if (prop == null)
41+
{
42+
System.out.println("Mapi property could not be found.");
43+
}
44+
else
45+
{
46+
//get the property data as string
47+
String strSubject = prop.getString();
48+
System.out.println("Subject: " + strSubject);
49+
}
50+
51+
//read internet code page property
52+
prop = (MapiProperty)coll.get_Item(MapiPropertyTag.PR_INTERNET_CPID);
53+
if (prop != null)
54+
{
55+
System.out.println("Code page: " + prop.getLong());
56+
}
57+
}
58+
catch(Exception ex)
59+
{
60+
System.out.println("Some error occurred while accessing outlook Mapi properties.");
61+
}
62+
}
63+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.msg;
10+
11+
import com.aspose.email.*;
12+
import com.aspose.email.examples.Utils;
13+
14+
public class ParsingAndSavingAttachments
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(ParsingAndSavingAttachments.class);
20+
21+
try
22+
{
23+
//Instantiate an MSG file to load an MSG file from disk
24+
MapiMessage outlookMessageFile=MapiMessage.fromFile(dataDir + "message.msg");
25+
26+
//Loop through the attachments collection associated with the MapiMessage object
27+
for(int i=0;i<outlookMessageFile.getAttachments().size();i++)
28+
{
29+
//Set a reference to the MapiAttachment object
30+
MapiAttachment outlookMessageAttachment = (MapiAttachment)outlookMessageFile.getAttachments().get_Item(i);
31+
32+
//Display attachment extension
33+
System.out.println("Att extension : " + outlookMessageAttachment.getExtension());
34+
35+
//Display attached file name
36+
System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
37+
38+
//Save attachment to the disk
39+
outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName());
40+
}
41+
}
42+
catch(Exception ex)
43+
{
44+
System.out.println(ex.toString());
45+
}
46+
}
47+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.msg;
10+
11+
import com.aspose.email.MapiAttachment;
12+
import com.aspose.email.MapiMessage;
13+
import com.aspose.email.MapiRecipient;
14+
import com.aspose.email.examples.Utils;
15+
16+
public class ParsingOutlookMessageFiles
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
// The path to the documents directory.
21+
String dataDir = Utils.getDataDir(ParsingOutlookMessageFiles.class);
22+
23+
try
24+
{
25+
//Instantiate an MSG file to load an MSG file from disk
26+
MapiMessage outlookMessageFile=MapiMessage.fromFile(dataDir + "message.msg");
27+
28+
//Display sender's name
29+
System.out.println("Sender Name : " + outlookMessageFile.getSenderName());
30+
31+
//Display Subject
32+
System.out.println("Subject : " + outlookMessageFile.getSubject());
33+
34+
//Display Body
35+
System.out.println("Body : " + outlookMessageFile.getBody());
36+
37+
//Display Recipient's info
38+
System.out.println("\nRecipients : \n");
39+
40+
//Loop through the recipients collection associated with the MapiMessage object
41+
for (int i=0; i<outlookMessageFile.getRecipients().size(); i++)
42+
{
43+
//Set a reference to the MapiRecipient object
44+
MapiRecipient rcp= (MapiRecipient) outlookMessageFile.getRecipients().get_Item(i);
45+
//Display recipient email address
46+
System.out.println("Email : " + rcp.getEmailAddress());
47+
//Display recipient name
48+
System.out.println("Name : " + rcp.getDisplayName());
49+
//Display recipient type
50+
System.out.println("Recipient Type : " + rcp.getRecipientType());
51+
}
52+
}
53+
catch(Exception ex)
54+
{
55+
System.out.println("Some error occurred while parsing the msg file.");
56+
}
57+
}
58+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.msg;
10+
11+
import com.aspose.email.*;
12+
import com.aspose.email.examples.Utils;
13+
14+
public class ReadOutlookTemplateFile
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(ReadOutlookTemplateFile.class);
20+
21+
// Load the Outlook template (OFT) file in MailMessage's instance
22+
MailMessage message = MailMessage.load(dataDir + "sample.oft", MailMessageLoadOptions.getDefaultMsg());
23+
24+
// Set the sender and recipients information
25+
String senderDisplayName = "John";
26+
String senderEmailAddress = "[email protected]";
27+
String recipientDisplayName = "William";
28+
String recipientEmailAddress = "[email protected]";
29+
30+
message.setSender(new MailAddress(senderEmailAddress, senderDisplayName));
31+
message.getTo().addMailAddress(new MailAddress(recipientEmailAddress, recipientDisplayName));
32+
33+
message.setHtmlBody(message.getHtmlBody().replace("DisplayName", "<b>" + recipientDisplayName + "</b>"));
34+
35+
// Set the name, location and time in email body
36+
String meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>";
37+
String meetingTime = "<u>" + "Monday, June 28, 2013" + "</u>";
38+
39+
message.setHtmlBody(message.getHtmlBody().replace("MeetingPlace", meetingLocation));
40+
message.setHtmlBody(message.getHtmlBody().replace("MeetingTime", meetingTime));
41+
42+
// Save the message in MSG format and open in Office Outlook
43+
MapiMessage mapimessage = MapiMessage.fromMailMessage(message);
44+
mapimessage.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
45+
mapimessage.save(dataDir + "invitation.msg");
46+
47+
System.out.println("Successfully created message file from template.");
48+
}
49+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.msg;
10+
11+
import com.aspose.email.*;
12+
import com.aspose.email.examples.Utils;
13+
14+
import java.text.SimpleDateFormat;
15+
import java.util.Date;
16+
17+
public class SettingFollowUpAndDueData
18+
{
19+
public static void main(String[] args) throws Exception
20+
{
21+
// The path to the documents directory.
22+
String dataDir = Utils.getDataDir(SettingFollowUpAndDueData.class);
23+
24+
//Instantiate an MSG file to load an MSG file from disk
25+
MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");
26+
27+
SimpleDateFormat rangeFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
28+
29+
Date startDate = rangeFormatter.parse("Mon, 20 May 2015 12:00");
30+
Date dueDate = rangeFormatter.parse("Tue, 21 May 2015 12:00");
31+
Date reminderTime = rangeFormatter.parse("Wed, 15 May 2015 21:50");
32+
33+
//Set up follow up flag with start date and due date
34+
FollowUpManager.setFlag(msg, "Follow up", startDate, dueDate);
35+
36+
// Add a flag with a reminder
37+
FollowUpOptions followUpOptions = new FollowUpOptions("Follow up", startDate, dueDate, reminderTime);
38+
FollowUpManager.setOptions(msg, followUpOptions);
39+
40+
// Add a flag to a message sent to someone else
41+
FollowUpManager.setFlagForRecipients(msg, "Follow up", reminderTime);
42+
43+
// Simultaneously flag a message both for yourself and the recipients
44+
followUpOptions = new FollowUpOptions("Follow up", startDate, dueDate, reminderTime);
45+
followUpOptions.setRecipientsFlagRequest("Follow up");
46+
followUpOptions.setRecipientsReminderTime(reminderTime);
47+
FollowUpManager.setOptions(msg, followUpOptions);
48+
49+
// Mark a message flag complete
50+
FollowUpManager.markAsCompleted(msg);
51+
52+
// Remove a flag
53+
FollowUpManager.clearFlag(msg);
54+
55+
// Read follow-up flag options from a message
56+
FollowUpOptions options = FollowUpManager.getOptions(msg);
57+
58+
System.out.println("Follow up options set successfully.");
59+
}
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Email. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.email.examples.outlook.pst;
10+
11+
import com.aspose.email.*;
12+
import com.aspose.email.examples.Utils;
13+
14+
public class CreateSaveOutlookFiles
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(CreateSaveOutlookFiles.class);
20+
21+
// Create an instance of MailMessage class
22+
MailMessage mailMsg = new MailMessage();
23+
24+
// Set FROM field of the message
25+
mailMsg.setFrom(new MailAddress("[email protected]"));
26+
27+
// Create an instance of MailAddressCollection
28+
MailAddressCollection addressCol = new MailAddressCollection();
29+
30+
// Add an address to MailAddressCollection
31+
addressCol.addMailAddress(new MailAddress("[email protected]"));
32+
33+
// Set the MailAddressCollection as TO field of the message
34+
mailMsg.setTo(addressCol);
35+
36+
// Set SUBJECT of the message
37+
mailMsg.setSubject("creating an outlook message file");
38+
39+
// Set BODY of the message
40+
mailMsg.setBody("This message is created by Aspose.Email for Java");
41+
42+
// Create an instance of MapiMessage class and pass MailMessage as argument
43+
MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg);
44+
45+
// Path and file name where message file will be saved
46+
String strMsgFile = dataDir + "message.msg";
47+
48+
// Save the message (msg) file
49+
outlookMsg.save(strMsgFile);
50+
51+
// Display Status.
52+
System.out.println("MSG file created and saved successfully.");
53+
}
54+
}

0 commit comments

Comments
 (0)