Last active
September 19, 2019 13:51
-
-
Save aspose-email/e3443fa9baa07df6d929fc4a408add67 to your computer and use it in GitHub Desktop.
This Gist contains code snippets of examples of Aspose.Email for Java.
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String location = "Room 5"; | |
java.util.Calendar c = java.util.Calendar.getInstance(); | |
c.set(2011, 11, 10, 10, 12, 11); | |
Date startDate = c.getTime(); | |
c.set(2012, 10, 13, 13, 11, 12); | |
Date endDate = c.getTime(); | |
MailAddress organizer = new MailAddress("aaa@amail.com", "Organizer"); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
MailAddress attendee1 = new MailAddress("bbb@bmail.com", "First attendee"); | |
MailAddress attendee2 = new MailAddress("ccc@cmail.com", "Second attendee"); | |
attendee1.setParticipationStatus(ParticipationStatus.Accepted); | |
attendee2.setParticipationStatus(ParticipationStatus.Declined); | |
attendees.addMailAddress(attendee1); | |
attendees.addMailAddress(attendee2); | |
Appointment target = new Appointment(location, startDate, endDate, organizer, attendees); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IcsSaveOptions saveOptions = new IcsSaveOptions(); | |
saveOptions.setAction(AppointmentAction.Create); | |
CalendarWriter writer = new CalendarWriter("WirteMultipleEventsToICS_out.ics", saveOptions); | |
//Set the start and end date of meeting | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2018, Calendar.JUNE, 19, 19, 0, 0); //19 Jan, 2015 - 1900 | |
Date startDate = calendar.getTime(); | |
calendar.set(2018, Calendar.JUNE, 19, 20, 0, 0); | |
Date endDate = calendar.getTime(); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addItem(new MailAddress("recepientEmail@gmail.com")); | |
try { | |
for (int i = 0; i < 10; i++) { | |
//create Appointment instance | |
Appointment app = new Appointment("Room 112", //location | |
startDate, //start time | |
endDate, //end time | |
new MailAddress("organizer@domain.com"), //organizer | |
attendees //attendee | |
); | |
app.setDescription("Test body " + i); | |
app.setSummary("Test summary:" + i); | |
writer.write(app); | |
} | |
} finally { | |
writer.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(AddAndRetrieveAttachmentFromCalendarItems.class) + "email/"; | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2016, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date startDate = calendar.getTime(); | |
calendar.set(2016, Calendar.DECEMBER, 1); | |
Date endDate = calendar.getTime(); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addMailAddress(new MailAddress("attendee_address@domain.com", "Attendee")); | |
WeeklyRecurrencePattern expected = new WeeklyRecurrencePattern(3); | |
Appointment app = new Appointment("Appointment Location", "Appointment Summary", "Appointment Description", startDate, endDate, new MailAddress("organizer_address@domain.com", "Organizer"), | |
attendees, expected); | |
//Attach a file from disc to this appointment | |
File file = new File(dataDir + "sample.xlsx"); | |
FileInputStream fis = new FileInputStream(file); | |
Attachment att = new Attachment(fis, file.getName()); | |
app.getAttachments().addItem(att); | |
fis.close(); | |
String savedFile = "appWithAttachments.ics"; | |
app.save(dataDir + savedFile, AppointmentSaveFormat.Ics); | |
Appointment app2 = Appointment.load(dataDir + savedFile); | |
System.out.println("Total Attachments: " + app2.getAttachments().size()); | |
for (int i = 0; i < app2.getAttachments().size(); i++) { | |
att = app2.getAttachments().get_Item(i); | |
System.out.println(att.getName()); | |
//Save the attachment to disc | |
att.save(dataDir + att.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(AddAttachmentToANewEmailMessage.class) + "email/"; | |
//Create an instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
//From | |
message.setFrom(new MailAddress("sender@sender.com")); | |
//To | |
message.getTo().addMailAddress(new MailAddress("receiver@gmail.com")); | |
//Adding 1st attachment | |
//Create an instance of Attachment class | |
Attachment attachment; | |
//Load an attachment | |
attachment = new Attachment(dataDir + "1.txt"); | |
//Add attachment in instance of MailMessage class | |
message.getAttachments().addItem(attachment); | |
//Add 2nd Attachment | |
message.getAttachments().addItem(new Attachment(dataDir + "1.jpg")); | |
//Add 3rd Attachment | |
message.getAttachments().addItem(new Attachment(dataDir + "1.doc")); | |
//Add 4th Attachment | |
message.getAttachments().addItem(new Attachment(dataDir + "1.rar")); | |
//Add 5th Attachment | |
message.getAttachments().addItem(new Attachment(dataDir + "1.pdf")); | |
//Save message to disc | |
message.save(dataDir + "AddAttachmentToANewEmailMessage_out.msg", SaveOptions.getDefaultMsg()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(AddEmbeddedImagesToEmailMessage.class) + "email/"; | |
// 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().addItem(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.getTo().addItem(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. It also contains <img> tag with cid. cid = LinkedResource.ContentID | |
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" + "<font color=blue>This line is in blue color</font><br><br>" + "Here is an embedded image.<img src=cid:companylogo>"); | |
// Add linked resource | |
LinkedResource res = new LinkedResource(dataDir + "barcode.png", MediaTypeNames.Image.PNG); | |
res.setContentId("companylogo"); | |
// Add Linked resource to the message’s Linked resource colledction | |
message.getLinkedResources().addItem(res); | |
// Save message in EML, MSG and MHTML formats | |
message.save(dataDir + "EmbeddedImageToEmail_out.eml"); | |
message.save(dataDir + "EmbeddedImageToEmail_out.msg"); | |
message.save(dataDir + "EmbeddedImageToEmail_out.mhtml"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(AddOrRemoveAttachmentFromAnExistingMessage.class) + "email/"; | |
//Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage message = MailMessage.load(dataDir + "EmailWithAttachment.eml"); | |
//Initialize AttachmentCollection object with MailMessage Attachments | |
AttachmentCollection attachments = message.getAttachments(); | |
System.out.println("Attachment Count: " + attachments.size()); | |
//Check if AttachmentCollection size is greater than 0 | |
if (attachments.size() > 0) { | |
//Remove Attachment from index location 0 | |
attachments.removeAt(0); | |
System.out.println("Attachment Count: " + attachments.size()); | |
} | |
//Add a PDF file as attachment to the message | |
message.addAttachment(new Attachment(dataDir + "1.pdf")); | |
System.out.println("Attachment Count: " + attachments.size()); | |
//Save the Email message to disk | |
message.save(dataDir + "AddRemoveAttachmentFromAnExistingMessage_out.eml", SaveOptions.getDefaultEml()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void main(String[] args) { | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(BayesianSpamAnalyzer.class) + "email/"; | |
SpamFilterTest(dataDir); | |
} | |
public static void SpamFilterTest(String dataDir) { | |
String hamFolder = dataDir + "ham"; | |
String spamFolder = dataDir + "spam"; | |
String testFolder = dataDir + "test"; | |
String dataBaseFile = dataDir + "SpamFilterDatabase.txt"; | |
teachAndCreateDatabase(hamFolder, spamFolder, dataBaseFile); | |
java.io.File folder = new java.io.File(testFolder); | |
java.io.File[] testFiles = folder.listFiles(); | |
SpamAnalyzer analyzer = new SpamAnalyzer(dataBaseFile); | |
for (int i = 0; i < testFiles.length; i++) { | |
MailMessage msg = MailMessage.load(testFiles[i].getAbsolutePath()); | |
System.out.println(msg.getSubject()); | |
double probability = analyzer.test(msg); | |
printResult(probability); | |
} | |
} | |
private static void teachAndCreateDatabase(String hamFolder, String spamFolder, String dataBaseFile) { | |
java.io.File folder = new java.io.File(hamFolder); | |
java.io.File[] hamFiles = folder.listFiles(); | |
folder = new java.io.File(spamFolder); | |
java.io.File[] spamFiles = folder.listFiles(); | |
SpamAnalyzer analyzer = new SpamAnalyzer(); | |
for (int i = 0; i < hamFiles.length; i++) { | |
MailMessage hamMailMessage; | |
try { | |
hamMailMessage = MailMessage.load(hamFiles[i].getAbsolutePath()); | |
} catch (Exception e) { | |
continue; | |
} | |
System.out.println(i); | |
analyzer.trainFilter(hamMailMessage, false); | |
} | |
for (int i = 0; i < spamFiles.length; i++) { | |
MailMessage spamMailMessage; | |
try { | |
spamMailMessage = MailMessage.load(spamFiles[i].getAbsolutePath()); | |
} catch (Exception e) { | |
continue; | |
} | |
System.out.println(i); | |
analyzer.trainFilter(spamMailMessage, true); | |
} | |
analyzer.saveDatabase(dataBaseFile); | |
} | |
private static void printResult(double probability) { | |
if (probability < 0.05) | |
System.out.println("This is ham)"); | |
else if (probability > 0.95) | |
System.out.println("This is spam)"); | |
else | |
System.out.println("Maybe spam)"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage message = new MailMessage("Sender Name <sender@from.com>", "Kyle Huang <kyle@to.com>"); | |
// A To address with a friendly name can also be specified like this | |
message.getTo().addMailAddress(new MailAddress("kyle@to.com", "Kyle Huang")); | |
// Specify Cc and Bcc email address along with a friendly name | |
message.getCC().addMailAddress(new MailAddress("guangzhou@cc.com", "Guangzhou Team")); | |
message.getBcc().addMailAddress(new MailAddress("ahaq@bcc.com", "Ammad ulHaq ")); | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password, Port | |
SmtpClient client = new SmtpClient(); | |
client.setHost("smtp.server.com"); | |
client.setUsername("Username"); | |
client.setPassword("Password"); | |
client.setPort(25); | |
try | |
{ | |
// Client.Send will send this message | |
client.send(message); | |
System.out.println("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create a message | |
MailMessage originalMsg = MailMessage.load(dataDir + "Message.msg", new MsgLoadOptions()); | |
if (originalMsg.isEncrypted() == true) | |
System.out.println("Its encrypted"); | |
else | |
System.out.println("Its NOT encrypted"); | |
// Encrypt the message | |
MailMessage mailMsg = null; | |
try { | |
mailMsg = originalMsg.encrypt(Files.readAllBytes(publicCertFilePath), ""); | |
if (mailMsg.isEncrypted() == true) | |
System.out.println("Its encrypted"); | |
else | |
System.out.println("Its NOT encrypted"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// Decrypt the message | |
try { | |
mailMsg = mailMsg.decrypt(Files.readAllBytes(privateCertFilePath), "password"); | |
if (mailMsg.isEncrypted() == true) | |
System.out.println("Its encrypted"); | |
else | |
System.out.println("Its NOT encrypted"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
// Save as Mht with header | |
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions(); | |
int iSaveOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader; | |
mhtSaveOptions.setMhtFormatOptions(iSaveOptions); | |
eml.save(dataDir + "ConvertingToMHTMLWithOptionalSettings_out.mht", mhtSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load(dataDir + "Message.msg", new MsgLoadOptions()); | |
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions(); | |
mhtSaveOptions.setSkipInlineImages(true); | |
eml.save(dataDir + "EmlToMhtmlWithoutInlineImages_out.mht", mhtSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
// Save as eml with preserved original boundares | |
EmlSaveOptions emlSaveOptions = new EmlSaveOptions(MailMessageSaveType.getEmlFormat()); | |
emlSaveOptions.setPreserveOriginalBoundaries(true); | |
eml.save(dataDir + "PreserveOriginalBoundaries_out.eml", emlSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage msg = MailMessage.load(dataDir + "test.eml", new EmlLoadOptions()); | |
// Save the Email message to disk by using the SaveOptions | |
msg.save(dataDir + "LoadAndSaveFileAsEML_out.eml", SaveOptions.getDefaultEml()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
//Save the Email message to disk in Unicode format | |
eml.save(dataDir + "LoadingEMLSavingToMSG_out.msg", SaveOptions.getDefaultMsgUnicode()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mailMsg = new MailMessage(); | |
mailMsg.setSubject("This is subject"); | |
mailMsg.setBody("This is body"); | |
String address = "a\"xasadf@xam.com"; | |
mailMsg.setFrom(new MailAddress(address)); | |
mailMsg.getTo().addMailAddress(new MailAddress(address)); | |
MapiConversionOptions cOpt = MapiConversionOptions.getUnicodeFormat(); | |
cOpt.setPreserveOriginalAddresses(true); | |
MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg, cOpt); | |
outlookMsg.save(dataDir + "PreservingOriginalEmailAddress_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Appointment appointment = Appointment.load(dataDir + "test.ics"); | |
MailMessage outlookMsg = new MailMessage(); | |
outlookMsg.addAlternateView(appointment.requestApointment()); | |
MhtSaveOptions opt = SaveOptions.getDefaultMhtml(); | |
opt.setMhtFormatOptions(opt.getMhtFormatOptions() | MhtFormatOptions.RenderCalendarEvent); | |
outlookMsg.save(dataDir + "RenderingCalendarEventsToMHTML_out.mht", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load(dataDir + "PreserveOriginalBoundaries.eml"); | |
// Save as eml with preserved thef attachment | |
EmlSaveOptions emlSaveOptions = new EmlSaveOptions(MailMessageSaveType.getEmlFormat()); | |
emlSaveOptions.setFileCompatibilityMode(FileCompatibilityMode.PreserveTnefAttachments); | |
eml.save(dataDir + "PreserveTNEFAttachment_out.eml", emlSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String fileName = dataDir + "EmailWithAttandEmbedded.eml"; | |
MailMessage eml = MailMessage.load(fileName); | |
//final String outDir = "out path"; | |
String outFileName = "EmailWithAttandEmbedded_out.html"; | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setEmbedResources(false); | |
options.setSaveResourceHandler(new SaveResourceHandler() { | |
@Override | |
public void invoke(AttachmentBase attachment, String[] resourcePath) { | |
String dataDir = Utils.getSharedDataDir(ConvertEmailMessages.class) + "email/"; | |
attachment.save(dataDir + attachment.getContentId()); | |
resourcePath[0] = dataDir + attachment.getContentId(); | |
} | |
}); | |
eml.save(dataDir + outFileName, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
// Save as msg with preserved dates | |
MsgSaveOptions msgSaveOptions = new MsgSaveOptions(MailMessageSaveType.getOutlookMessageFormatUnicode()); | |
msgSaveOptions.setPreserveOriginalDates(true); | |
eml.save(dataDir + "SavingAsMSGWithPreservedDates_out.msg", msgSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
eml.save(dataDir + "SavingMailMessageAsMHTML_out.mthml", SaveOptions.getDefaultMhtml()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage msg = MailMessage.load(dataDir + "Message.msg"); | |
msg.save(dataDir + "SavingMessageAsHTML_out1.html", SaveOptions.getDefaultHtml()); | |
//or | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
HtmlSaveOptions options = SaveOptions.getDefaultHtml(); | |
options.setEmbedResources(false); | |
options.setHtmlFormatOptions(HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress); | |
eml.save(dataDir + "SavingMessageAsHTML_out2.html", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "Message.msg"); | |
for (MapiRecipient rec : msg.getRecipients()) { | |
rec.getRecipientTrackStatus(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(CreateNewEmail.class) + "email/"; | |
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message | |
message.setSubject("New message created by Aspose.Email for Java"); | |
// Set Html body | |
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" + "<font color=blue>This line is in blue color</font>"); | |
// Set sender information | |
message.setFrom(new MailAddress("from@domain.com", "Sender Name", false)); | |
// Add TO recipients | |
message.getTo().addMailAddress(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.getTo().addMailAddress(new MailAddress("to2@domain.com", "Recipient 2", false)); | |
//Add CC recipients | |
message.getCC().addMailAddress(new MailAddress("cc1@domain.com", "Recipient 3", false)); | |
message.getCC().addMailAddress(new MailAddress("cc2@domain.com", "Recipient 4", false)); | |
// Save message in EML, MSG and MHTML formats | |
message.save(dataDir + "Message_out.eml", SaveOptions.getDefaultEml()); | |
message.save(dataDir + "Message_out.msg", SaveOptions.getDefaultMsg()); | |
message.save(dataDir + "Message_out.mhtml", SaveOptions.getDefaultMhtml()); | |
//Save as OFT | |
try { | |
MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode(); | |
options.setSaveAsTemplate(true); | |
message.save(dataDir + "emlToOft_out.oft", options); | |
} finally { | |
if (message != null) | |
((IDisposable) message).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateNewEmail.class); | |
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message | |
message.setSubject("New message created by Aspose.Email for Java"); | |
// Set Html body | |
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" + | |
"<font color=blue>This line is in blue color</font>"); | |
// Set sender information | |
message.setFrom(new MailAddress("from@domain.com", "Sender Name", false)); | |
// Add TO recipients | |
message.getTo().addMailAddress(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.getTo().addMailAddress(new MailAddress("to2@domain.com", "Recipient 2", false)); | |
//Add CC recipients | |
message.getCC().addMailAddress(new MailAddress("cc1@domain.com", "Recipient 3", false)); | |
message.getCC().addMailAddress(new MailAddress("cc2@domain.com", "Recipient 4", false)); | |
// Save message in EML, MSG and MHTML formats | |
message.save(dataDir + "Message.eml", SaveOptions.getDefaultEml()); | |
message.save(dataDir + "Message.msg", SaveOptions.getDefaultMsg()); | |
message.save(dataDir + "Message.mhtml", SaveOptions.getDefaultMhtml()); | |
//Save as OFT | |
try | |
{ | |
MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode(); | |
options.setSaveAsTemplate(true); | |
message.save("emlToOft.oft", options); | |
} | |
finally { if (eml != null) | |
((IDisposable)eml).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(DetectingFileFormat.class) + "email/"; | |
//Detect file format | |
FileFormatInfo info = FileFormatUtil.detectFileFormat(dataDir + "Message.msg"); | |
//Gets the detected load format | |
System.out.println("The message format is: " + info.getFileFormatType()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(DetermineIfAttachmentIsEmbeddedMessage.class) + "email/"; | |
MailMessage eml = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml"); | |
if (eml.getAttachments().get_Item(0).isEmbeddedMessage()) { | |
System.out.println("Attachment is an embedded message"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create a loop to display the no. of attachments present in email message | |
for (Attachment attachment : message.getAttachments()) | |
{ | |
// Save your attachments here and Display the the attachment file name | |
attachment.save(dataDir + attachment.getName()); | |
System.out.println(attachment.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(DisplayEmailInformation.class) + "email/"; | |
//Create MailMessage instance by loading an Eml file | |
MailMessage message = MailMessage.load(dataDir + "test.eml"); | |
System.out.print("From: "); | |
//Gets the sender info | |
System.out.println(message.getFrom()); | |
System.out.print("To: "); | |
//Gets the recipients info | |
System.out.println(message.getTo()); | |
System.out.print("Subject: "); | |
//Gets the subject | |
System.out.println(message.getSubject()); | |
System.out.print("HtmlBody: "); | |
//Gets the htmlbody | |
System.out.println(message.getHtmlBody()); | |
System.out.print("TextBody: "); | |
//Gets the textbody | |
System.out.println(message.getBody()); | |
System.out.print("HtmlBodyText: "); | |
//Gets the textbody from HTML | |
System.out.println(message.getHtmlBodyText()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(DisplayEmailInformation.class) + "email/"; | |
//Create MailMessage instance by loading an Eml file | |
MailMessage message = MailMessage.load(dataDir + "test.eml"); | |
System.out.print("From: "); | |
//Gets the sender info | |
System.out.println(message.getFrom()); | |
System.out.print("To: "); | |
//Gets the recipients info | |
System.out.println(message.getTo()); | |
System.out.print("Subject: "); | |
//Gets the subject | |
System.out.println(message.getSubject()); | |
System.out.print("HtmlBody: "); | |
//Gets the htmlbody | |
System.out.println(message.getHtmlBody()); | |
System.out.print("TextBody: "); | |
//Gets the textbody | |
System.out.println(message.getTextBody()); | |
System.out.print("HtmlBodyText: "); | |
//Gets the textbody from HTML | |
System.out.println(message.getHtmlBodyText()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String sender = "test@gmail.com"; | |
String recipient = "test@email.com"; | |
MailMessage message = new MailMessage(sender, recipient, "", ""); | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2016, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date startDate = calendar.getTime(); | |
calendar.set(2016, Calendar.DECEMBER, 1); | |
Date endDate = calendar.getTime(); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addMailAddress(new MailAddress("attendee_address@aspose.com", "Attendee")); | |
//WeeklyRecurrencePattern expected = new WeeklyRecurrencePattern(3); | |
Appointment app = new Appointment("", startDate, endDate, new MailAddress("organizer_address@aspose.com", "Organizer"), attendees); | |
/* | |
* Appointment app = new Appointment("Appointment Location", | |
* "Appointment Summary", "Appointment Description", startDate, endDate, | |
* new MailAddress("organizer_address@aspose.com", "Organizer"), | |
* attendees, expected); | |
*/ | |
//Set the Appointment as Draft | |
app.setMethod(AppointmentMethodType.Publish); | |
message.addAlternateView(app.requestApointment()); | |
MapiMessage msg = MapiMessage.fromMailMessage(message); | |
// Save the appointment as draft. | |
msg.save(dataDir + "appointment-draft.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String ical = "BEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nATTENDEE;CN=test@gmail.com:mailto:test@gmail.com\r\nDTSTART:20130220T171439\r\nDTEND:20130220T174439\r\nDTSTAMP:20130220T161439Z\r\nEND:VEVENT\r\nEND:VCALENDAR"; | |
String sender = "test@gmail.com"; | |
String recipient = "test@email.com"; | |
MailMessage message = new MailMessage(sender, recipient, "", ""); | |
AlternateView av = AlternateView.createAlternateViewFromString(ical, new ContentType("text/calendar")); | |
message.getAlternateViews().addItem(av); | |
MapiMessage msg = MapiMessage.fromMailMessage(message); | |
// Save the appointment as draft. | |
msg.save(dataDir + "DraftAppointment.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
//Create MailMessage instance by loading an EML file | |
MailMessage message = MailMessage.load(dataDir + "test.eml"); | |
System.out.println("Printing all Headers:\n\n"); | |
//Print out all the headers | |
for (int i=0; i< message.getHeaders().size(); i++) | |
System.out.println(message.getHeaders().get(i)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mail = MailMessage.load(dataDir + "test.eml"); | |
String decodedValue = mail.getHeaders().getDecodedValue("Thread-Topic"); | |
System.out.println(decodedValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Insert Header at Specific Location | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
eml.getHeaders().insert("Received", "Value"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message | |
message.setSubject("New message created by Aspose.Email for Java"); | |
// Set Html body | |
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" + | |
"<font color=blue>This line is in blue color</font>"); | |
// Set sender information | |
message.setFrom(new MailAddress("from@domain.com", "Sender Name", false)); | |
// Add TO recipients | |
message.getTo().addItem(new MailAddress("to@domain.com", "Recipient 1", false)); | |
// Message subject | |
message.setSubject("Customizing Email Headers"); | |
// Specify Date | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
Date date = calendar.getTime(); | |
message.setDate(date); | |
// Specify XMailer | |
message.setXMailer("Aspose.Email"); | |
// Specify Secret Header | |
message.getHeaders().add("secret-header", "mystery"); | |
// Save message to disc | |
message.save(dataDir + "SetEmailHeaders_out.msg", SaveOptions.getDefaultMsg()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String publicCertFileName = dataDir + "MyKey.cer"; | |
String privateCertFileName = dataDir + "MyPFX.pfx"; | |
Path publicCertFilePath = Paths.get(publicCertFileName); | |
Path privateCertFilePath = Paths.get(privateCertFileName); | |
// Create a message | |
MailMessage msg = new MailMessage("atneostthaecrcount@gmail.com", "atneostthaecrcount@gmail.com", "Test subject", "Test Body"); | |
// Encrypt the message | |
MailMessage eMsg = null; | |
try { | |
eMsg = msg.encrypt(Files.readAllBytes(publicCertFilePath), ""); | |
if (eMsg.isEncrypted() == true) | |
System.out.println("Its encrypted"); | |
else | |
System.out.println("Its NOT encrypted"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// Decrypt the message | |
MailMessage dMsg = null; | |
try { | |
dMsg = eMsg.decrypt(Files.readAllBytes(privateCertFilePath), "password"); | |
if (dMsg.isEncrypted() == true) | |
System.out.println("Its encrypted"); | |
else | |
System.out.println("Its NOT encrypted"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
eml.save(dataDir + "testEml_out.eml", SaveOptions.getDefaultEml()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage msg = MailMessage.load(filename, new MsgLoadOptions()); | |
msg.setDate(new Date()); | |
// Set the timezone offset in seconds | |
msg.setTimeZoneOffset(5*60*60*1000); | |
MhtSaveOptions mhtOptions = new MhtSaveOptions(); | |
mhtOptions.setMhtFormatOptions(MhtFormatOptions.WriteHeader); | |
msg.save(dataDir + "ExportToMHTWithCustomTimezone_out.mhtml", mhtOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ExtractAttachments.class) + "email/"; | |
//Initialize and Load an existing EML file | |
MailMessage msg = MailMessage.load(dataDir + "EmailWithAttachment.eml", new EmlLoadOptions()); | |
//Initialize AttachmentCollection object with MailMessage Attachments | |
AttachmentCollection attachments = msg.getAttachments(); | |
//Iterate over the AttachmentCollection | |
for (int index = 0; index < attachments.size(); index++) { | |
//Initialize Attachment object and Get the indexed Attachment reference | |
Attachment attachment = (Attachment) attachments.get_Item(index); | |
//Display Attachment Name | |
System.out.println(attachment.getName()); | |
//Save Attachment to disk | |
attachment.save(dataDir + "attachment_" + attachment.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
static void ExtractInlineAttachments(String dataDir) | |
{ | |
MapiMessage message = MapiMessage.fromFile(dataDir + "MSG file with RTF Formatting.msg"); | |
MapiAttachmentCollection attachments = message.getAttachments(); | |
for (Object untypedAttachment : attachments) | |
{ | |
MapiAttachment attachment = (MapiAttachment) untypedAttachment; | |
if(IsAttachmentInline(attachment)) | |
{ | |
try | |
{ | |
SaveAttachment(attachment, UUID.randomUUID().toString()); | |
} | |
catch (IOException e) | |
{ | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
static boolean IsAttachmentInline(MapiAttachment attachment) | |
{ | |
MapiObjectProperty objectData = attachment.getObjectData(); | |
if (objectData == null) | |
return false; | |
for (Object prop : attachment.getObjectData().getProperties().getValues()) | |
{ | |
MapiProperty property = (MapiProperty)prop; | |
if ("\u0003ObjInfo".equals(property.getName())) | |
{ | |
byte[] data = property.getData(); | |
int odtPersist1 = data[1] << 8 | data[0]; | |
return (odtPersist1 & 0x40) == 0; | |
} | |
} | |
return false; | |
} | |
static void SaveAttachment(MapiAttachment attachment, String fileName) throws IOException, FileNotFoundException | |
{ | |
for (Object prop : attachment.getObjectData().getProperties().getValues()) | |
{ | |
MapiProperty property = (MapiProperty)prop; | |
if ("Package".equals(property.getName())) | |
{ | |
FileOutputStream fs; | |
try | |
{ | |
fs = new FileOutputStream(fileName); | |
fs.write(property.getData(), 0, property.getData().length); | |
} | |
catch (java.io.IOException e) | |
{ | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Appointment appointment = Appointment.load(dataDir + "test.ics"); | |
AppointmentFormattingOptions formattingOptions = AppointmentFormattingOptions.createAsHtml(); | |
formattingOptions.setLocationFormat("<FONT SIZE=2 FACE=\"Arial\"><b>Where: {0}</b></FONT><BR>"); | |
formattingOptions.setTitleFormat("<FONT SIZE=2 FACE=\"Arial\"><b>Subject: {0}</b></FONT><BR>"); | |
formattingOptions.setDescriptionFormat("<P><FONT SIZE=2 FACE=\"Arial\">-----------<br><i>{0}</i></FONT></P>"); | |
System.out.println(appointment.getAppointmentText(formattingOptions)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Appointment appointment = Appointment.load(dataDir + "test.ics"); | |
AppointmentFormattingOptions formattingOptions = new AppointmentFormattingOptions(); | |
formattingOptions.setLocationFormat("Where: {0}"); | |
formattingOptions.setTitleFormat("Subject: {0}"); | |
formattingOptions.setDescriptionFormat("\r\n*~*~*~*~*~*~*~*~*~*\r\n{0}"); | |
System.out.println(appointment.getAppointmentText(formattingOptions)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Loading with default options | |
// Load from eml | |
MailMessage eml = MailMessage.load("test.eml", new EmlLoadOptions()); | |
// Load from html | |
MailMessage html = MailMessage.load("test.html", new HtmlLoadOptions()); | |
// load from mhtml | |
MailMessage mhtml = MailMessage.load("test.mhtml", new MhtmlLoadOptions()); | |
// load from msg | |
MailMessage msg = MailMessage.load("test.msg", new MsgLoadOptions()); | |
// load from thef fomat | |
MailMessage thef = MailMessage.load("winmail.dat", new TnefLoadOptions()); | |
// Loading with custom options | |
EmlLoadOptions opt = new EmlLoadOptions(); | |
opt.setPreserveTnefAttachments(true); | |
MailMessage emlMailMessage = MailMessage.load("test.html", opt); | |
HtmlLoadOptions htmlOpt = new HtmlLoadOptions(); | |
htmlOpt.shouldAddPlainTextView(true); | |
MailMessage htmlMailMessage = MailMessage.load("test.html", htmlOpt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ModifyAnExistingEmailMessage.class) + "email/"; | |
//Initialize and Load an existing MSG file by specifying the MessageFormat | |
MailMessage email = MailMessage.load(dataDir + "Message.msg"); | |
//Initialize a String variable to get the Email Subject | |
String subject = email.getSubject(); | |
//Append some more information to Subject | |
subject = subject + " This text is added to the existing subject"; | |
//Set the Email Subject | |
email.setSubject(subject); | |
//Initialize a String variable to get the Email's HTML Body | |
String body = email.getHtmlBody(); | |
//Apppend some more information to the Body variable | |
body = body + "<br> This text is added to the existing body"; | |
//Set the Email Body | |
email.setHtmlBody(body); | |
//Initialize MailAddressCollection object | |
MailAddressCollection contacts = new MailAddressCollection(); | |
//Retrieve Email's TO list | |
contacts = email.getTo(); | |
//Check if TO list has some values | |
if (contacts.size() > 0) { | |
//Remove the first email address | |
contacts.removeAt(0); | |
//Add another email address to collection | |
contacts.add("to1@domain.com"); | |
} | |
//Set the collection as Email's TO list | |
email.setTo(contacts); | |
//Initialize MailAddressCollection | |
contacts = new MailAddressCollection(); | |
//Retrieve Email's CC list | |
contacts = email.getCC(); | |
//Add another email address to collection | |
contacts.add("cc2@domain.com"); | |
//Set the collection as Email's CC list | |
email.setCC(contacts); | |
//Save the Email message to disk | |
email.save(dataDir + "ModifingAnExistingEmailMessage_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void main(String[] args) { | |
//create a new MailMessage instance as a template | |
MailMessage template = new MailMessage(); | |
//add template field to subject | |
template.setSubject("Hello, #FirstName#"); | |
template.setFrom(MailAddress.to_MailAddress("sale@aspose.com")); | |
//add template field to receipt | |
template.getTo().addMailAddress(new MailAddress("#Receipt#", true)); | |
//add template field to html body | |
//use GetSignment as the template routine, which will provide the same signment. | |
template.setHtmlBody("Dear #FirstName# #LastName#, <br><br>Thank you for your interest in <STRONG>Aspose.Network</STRONG>.<br><br>Have fun with it.<br><br>#GetSignature()#"); | |
//create a new TemplateEngine with the template message. | |
TemplateEngine engine = new TemplateEngine(template); | |
//register the GetSignment as a template routine, for we use it in the template. | |
engine.registerRoutine("GetSignature", new TemplateRoutine() { | |
public Object invoke(Object[] args) { | |
return getSignature(args); | |
} | |
}); | |
//fill a DataTable as data source | |
DataTable dt = new DataTable(); | |
dt.getColumns().add("Receipt"); | |
dt.getColumns().add("FirstName"); | |
dt.getColumns().add("LastName"); | |
DataRow dr; | |
dr = dt.newRow(); | |
dr.set("Receipt", "Nancy.Davolio<Nancy@somedomain.com>"); | |
dr.set("FirstName", "Nancy"); | |
dr.set("LastName", "Davolio"); | |
dt.getRows().add(dr); | |
dr = dt.newRow(); | |
dr.set("Receipt", "Andrew.Fuller<Andrew@somedomain.com>"); | |
dr.set("FirstName", "Andrew"); | |
dr.set("LastName", "Fuller"); | |
dt.getRows().add(dr); | |
dr = dt.newRow(); | |
dr.set("Receipt", "Janet.Leverling<Janet@somedomain.com>"); | |
dr.set("FirstName", "Janet"); | |
dr.set("LastName", "Leverling"); | |
dt.getRows().add(dr); | |
MailMessageCollection messages; | |
try | |
{ | |
//create the messages from the template and datasource. | |
messages = engine.instantiate(dt); | |
} | |
catch (MailException ex) | |
{ | |
System.out.println(ex.toString()); | |
} | |
} | |
public static Object getSignature(Object[] args) { | |
return "John Smith<br>Product Lead<br>Aspose Ltd.<br>".concat(DateTime.getNow().toShortDateString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(DisplayEmailInformation.class) + "email/"; | |
EmlLoadOptions options = new EmlLoadOptions(); | |
options.setPreserveEmbeddedMessageFormat(true); | |
MailMessage mail = MailMessage.load(dataDir + "tnefWithMsgInside.eml", options); | |
int fileFormat = FileFormatUtil.detectFileFormat(mail.getAttachments().get_Item(0).getContentStream()).getFileFormatType(); | |
System.out.println("Embedded message file format: " + fileFormat); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = MailMessage.load("path", new EmlLoadOptions()); | |
MapiConversionOptions options = MapiConversionOptions.getUnicodeFormat(); | |
options.setPreserveEmbeddedMessageFormat(true); | |
MapiMessage msg = MapiMessage.fromMailMessage(eml, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ProcessBouncedMessages.class) + "email/"; | |
String fileName = "failed.msg"; | |
MailMessage mail = MailMessage.load(dataDir + fileName); | |
BounceResult result = mail.checkBounced(); | |
System.out.println(fileName); | |
System.out.println("IsBounced : " + result.isBounced()); | |
System.out.println("Action : " + result.getAction()); | |
System.out.println("Recipient : " + result.getRecipient()); | |
System.out.println(); | |
fileName = "failed1.msg"; | |
mail = MailMessage.load(dataDir + fileName); | |
result = mail.checkBounced(); | |
System.out.println(fileName); | |
System.out.println("IsBounced : " + result.isBounced()); | |
System.out.println("Action : " + result.getAction()); | |
System.out.println("Recipient : " + result.getRecipient()); | |
System.out.println("Reason : " + result.getReason()); | |
System.out.println("Status : " + result.getStatus()); | |
System.out.println("OriginalMessage ToAddress 1: " + result.getOriginalMessage().getTo().get_Item(0).getAddress()); | |
System.out.println(); | |
fileName = "test.eml"; | |
mail = MailMessage.load(dataDir + fileName); | |
result = mail.checkBounced(); | |
System.out.println(fileName); | |
System.out.println("IsBounced : " + result.isBounced()); | |
System.out.println("Action : " + result.getAction()); | |
System.out.println("Recipient : " + result.getRecipient()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void main(String[] args) { | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ReadEmbeddedEmailAttachmentsFromMessage.class) + "email/"; | |
try { | |
MailMessage message = MailMessage.load(dataDir + "EmailWithAttandEmbedded.eml"); | |
parseMessage(message, dataDir); | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} | |
} | |
private static void parseMessage(MailMessage message, String dataDir) { | |
System.out.println("Subject: " + message.getSubject()); | |
System.out.println("Extracting attachments...."); | |
for (int i = 0; i < message.getAttachments().size(); i++) { | |
Attachment att = (Attachment) message.getAttachments().get_Item(i); | |
System.out.println("Attachment Name: " + att.getName()); | |
// Get the name of attachment. If msg subject contains characters like :, /, \ etc., replace with space | |
// because windows cannot save files with these characters also save first 50 characters as file name to avoid long file names | |
String attFileName = att.getName().replace(".eml", "").replace(":", " ").replace("\\", " ").replace("/", " ").replace("?", ""); | |
if (attFileName.length() > 50) { | |
attFileName = attFileName.substring(0, 50); | |
} | |
String attExt = (att.getName().substring(att.getName().lastIndexOf("."), att.getName().lastIndexOf(".") + 4)); | |
// Save the attachment to disk | |
att.save(dataDir + attFileName + attExt); | |
// Check if it is an orphaned text attachment file (ATT00001.txt....) and of type eml | |
if ((attExt.equals(".eml")) || (att.getContentType().getMediaType().equals("text/plain") && att.getName().contains(".txt") == true && att.getName().contains("ATT") == true)) { | |
// Try to load this text file in MailMessage | |
MailMessage attMsg = MailMessage.load(dataDir + attFileName + attExt); | |
// Call the function recursively to parse this message and attachments | |
ParseMessage(attMsg, dataDir); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
EmlLoadOptions options = new EmlLoadOptions(); | |
// This will Preserve the TNEF attachment as it is, file contains the TNEF attachment | |
options.setPreserveTnefAttachments(true); | |
MailMessage eml = MailMessage.load(dataDir + "tnefEml.eml", options); | |
for (Attachment attachment : eml.getAttachments()) | |
{ | |
System.out.println(attachment.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(DisplayEmailInformation.class) + "email/"; | |
List<Appointment> appointments = new ArrayList<Appointment>(); | |
CalendarReader reader = new CalendarReader(dataDir + "US-Holidays.ics"); | |
while (reader.nextEvent()) | |
{ | |
appointments.add(reader.getCurrent()); | |
} | |
System.out.println("Number of events read: " + appointments.size()); | |
//Process appointments loaded from events | |
//Reading events from a specific index | |
appointments = new ArrayList<Appointment>(); | |
AppointmentLoadOptions options = new AppointmentLoadOptions(); | |
options.setEventIndex(4); | |
reader = new CalendarReader(dataDir + "US-Holidays.ics", options); | |
//start reading from 4th appointment... | |
while (reader.nextEvent()) | |
{ | |
appointments.add(reader.getCurrent()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String fileName = "test.eml"; | |
MailMessage msg = MailMessage.load(fileName); | |
msg.getLinkedResources().removeAt(0, true); | |
msg.getAlternateViews().get_Item(0).getLinkedResources().clear(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(RenderingCalendarEvents.class) + "email/"; | |
MailMessage msg = MailMessage.load(dataDir + "Meeting with Recurring Occurrences.msg"); | |
MhtSaveOptions options = new MhtSaveOptions(); | |
{ | |
options.setMhtFormatOptions(MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderCalendarEvent); | |
//Format the output details if required - optional | |
//Set the display for Start Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.START)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.START,"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.START, "<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for End Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.END)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.END, "<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.END, "<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for Recurrence Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.RECURRENCE)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.RECURRENCE,"<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.RECURRENCE, "<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for RecurrencePattern Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.RECURRENCE_PATTERN)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.RECURRENCE_PATTERN, "<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.RECURRENCE_PATTERN, "<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for Organizer Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.ORGANIZER)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.ORGANIZER, "<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.ORGANIZER, "<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for RequiredAttendees Property | |
if (options.getFormatTemplates().containsKey(MhtTemplateName.REQUIRED_ATTENDEES)) | |
options.getFormatTemplates().set_Item(MhtTemplateName.REQUIRED_ATTENDEES, "<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>"); | |
else | |
options.getFormatTemplates().add(MhtTemplateName.REQUIRED_ATTENDEES, "<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>"); | |
}; | |
msg.save(dataDir + "Meeting with Recurring Occurrences_out.mhtml", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify From, To, HtmlBody, DeliveryNotificationOptions field | |
message.setFrom(new MailAddress("sender@sender.com")); | |
message.getTo().add("receiver@receiver.com"); | |
message.setHtmlBody("<html><body>This is the Html body</body></html>"); | |
message.setDeliveryNotificationOptions(DeliveryNotificationOptions.OnSuccess); | |
message.getHeaders().add("Return-Receipt-To", "sender@sender.com"); | |
message.getHeaders().add("Disposition-Notification-To", "sender@sender.com"); | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
client.setHost("smtp.server.com"); | |
client.setUsername("Username"); | |
client.setPassword("Password"); | |
client.setPort(25); | |
try | |
{ | |
// Client.Send will send this message | |
client.send(message); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(RetrieveContentDescriptionInformationFromAttachmentHeaders.class) + "email/"; | |
MailMessage msg = MailMessage.load(dataDir + "EmailWithAttachment.eml"); | |
String description = msg.getAttachments().get_Item(0).getHeaders().get_Item("Content-Description"); | |
System.out.println("Description: " + description); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(SaveMessageAsDraft.class) + "email/"; | |
// 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().addMailAddress(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.getTo().addMailAddress(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(dataDir + "New-Draft.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage eml = new MailMessage("test@from.to", "test@to.to", "template subject", "Template body"); | |
String oftEmlFileName = "EmlAsOft_out.oft"; | |
MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode(); | |
options.setSaveAsTemplate(true); | |
eml.save(dataDir + oftEmlFileName, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Creates AlternateView to view an email message using the content specified in the //string | |
AlternateView alternate = AlternateView.createAlternateViewFromString("Alternate Text"); | |
// Adding alternate text | |
message.getAlternateViews().addItem(alternate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify HtmlBody | |
message.setHtmlBody("<html><body>This is the HTML body</body></html>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ShowHideExtraPrintHeaders.class) + "email/"; | |
String pageHeader = "<div><div class='pageHeader'>"Panditharatne, Mithra" <mithra.panditharatne@cibc.com><hr/></div>"; | |
MailMessage message = MailMessage.load(dataDir + "Message.eml"); | |
MhtMessageFormatter mailFormatter = new MhtMessageFormatter(); | |
int options = MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.WriteCompleteEmailAddress; | |
mailFormatter.format(message, options); | |
if (!message.getHtmlBody().contains(pageHeader)) | |
System.out.println("True"); | |
else | |
System.out.println("False"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String privateKeyFile = "key2.pem"; | |
RSACryptoServiceProvider rsa = PemReader.getPrivateKey(privateKeyFile); | |
DKIMSignatureInfo signInfo = new DKIMSignatureInfo("test", "yandex.ru"); | |
signInfo.getHeaders().addItem("From"); | |
signInfo.getHeaders().addItem("Subject"); | |
MailMessage mailMessage = new MailMessage("sender@gmail.com", "test@gmail.com"); | |
mailMessage.setSubject("Signed DKIM message text body"); | |
mailMessage.setBody("This is a text body signed DKIM message"); | |
MailMessage signedMsg = mailMessage.dKIMSign(rsa, signInfo); | |
try | |
{ | |
SmtpClient client = new SmtpClient("smtp.domain.com",25, "username", "password"); | |
client.send(signedMsg); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} | |
finally | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify ReplyTo, from, To, Message subject and secret header field | |
message.getReplyToList().add("reply@reply.com"); | |
message.setFrom(new MailAddress("sender@sender.com")); | |
message.getTo().add("receiver1@receiver.com"); | |
message.setSubject("test mail"); | |
message.getHeaders().add("secret-header", "mystery"); | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
client.setHost("smtp.server.com"); | |
client.setUsername("Username"); | |
client.setPassword("Password"); | |
client.setPort(25); | |
try | |
{ | |
// Client.Send will send this message | |
client.send(message); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify From, To, HtmlBody, BodyEncoding field | |
message.setFrom(new MailAddress("sender@sender.com")); | |
message.getTo().add("receiver@receiver.com"); | |
message.setHtmlBody("<html><body>This is the Html body</body></html>"); | |
message.setBodyEncoding(Charset.forName("US-ASCII")); | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
client.setHost("smtp.server.com"); | |
client.setUsername("Username"); | |
client.setPassword("Password"); | |
client.setPort(25); | |
try | |
{ | |
// Client.Send will send this message | |
client.send(message); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Declare message as MailMessage instance | |
// Create an Instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Specify From address | |
message.setFrom(new MailAddress("sender@sender.com")); | |
// Specify recipients’ mail addresses | |
MailAddressCollection toList = new MailAddressCollection(); | |
toList.add("receiver1@receiver.com"); | |
toList.add("receiver2@receiver.com"); | |
toList.add("receiver3@receiver.com"); | |
message.setTo(toList); | |
// Specify CC addresses | |
MailAddressCollection ccList = new MailAddressCollection(); | |
ccList.add("CC1@receiver.com"); | |
ccList.add("CC2@receiver.com"); | |
message.setCC(ccList); | |
// Specify BCC addresses | |
MailAddressCollection bccList = new MailAddressCollection(); | |
bccList.add("Bcc1@receiver.com"); | |
bccList.add("Bcc2@receiver.com"); | |
message.setBcc(bccList); | |
// Create an instance of SmtpClient Class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing host server, Username, Password, Port | |
client.setHost("smtp.server.com"); | |
client.setUsername("Username"); | |
client.setPassword("Password"); | |
client.setPort(25); | |
try | |
{ | |
// Client.Send will send this message | |
client.send(message); | |
// Display ‘Message Sent’, only if message sent successfully | |
System.out.println("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String fileName = "MainMessage.eml"; | |
String attachName = "barcode.png"; | |
String outFileName = "test_out.eml"; | |
FileInputStream fi = new FileInputStream(dataDir + attachName); | |
MailMessage eml = MailMessage.load(dataDir + fileName); | |
eml.getAttachments().addItem(new Attachment(fi, "barcode.png", "image/png")); | |
eml.save(dataDir + outFileName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MsgLoadOptions msgLoadOptions = new MsgLoadOptions(); | |
// The PreserveTnefAttachments option with MessageFormat.Msg will create the TNEF eml. | |
msgLoadOptions.setPreserveTnefAttachments(true); | |
MailMessage eml = MailMessage.load(dataDir + "test.eml", msgLoadOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "Message.msg"); | |
MailConversionOptions options = new MailConversionOptions(); | |
options.setConvertAsTnef (true); | |
MailMessage mail = msg.toMailMessage(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mail = MailMessage.load(dataDir + "test.eml"); | |
boolean isTnef = mail.getOriginalIsTnef(); | |
System.out.println("isTnef: " + isTnef); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void TestUpdateResources(String dataDir) | |
{ | |
String fileName = dataDir + "tnefEMl1.eml"; | |
String imgFileName = dataDir + "Untitled.jpg"; | |
String outFileName = dataDir + "01_SAVE_Preserve_out.eml"; | |
MailMessage originalMailMessage = MailMessage.load(fileName); | |
EmlLoadOptions emlOp = new EmlLoadOptions(); | |
UpdateResources(originalMailMessage, imgFileName); | |
EmlSaveOptions emlSo = new EmlSaveOptions(MailMessageSaveType.getEmlFormat()); | |
emlSo.setFileCompatibilityMode(FileCompatibilityMode.PreserveTnefAttachments); | |
originalMailMessage.save(outFileName, emlSo); | |
} | |
private static void UpdateResources(MailMessage msg, String imgFileName) | |
{ | |
for (int i = 0; i < msg.getAttachments().size(); i++) | |
{ | |
if (msg.getAttachments().get_Item(i).getContentType().getName().endsWith("jpg")) | |
{ | |
try { | |
File attFile = new File(imgFileName); | |
msg.getAttachments().get_Item(i).setContentStream(new FileInputStream(attFile)); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
else if (msg.getAttachments().get_Item(i).getContentType().getName().endsWith("eml")) | |
{ | |
ByteArrayOutputStream ms = new ByteArrayOutputStream(); | |
msg.getAttachments().get_Item(i).save(ms); | |
//ms.reset(); | |
ByteArrayInputStream ims = new ByteArrayInputStream(ms.toByteArray()); | |
MailMessage embeddedMessage = MailMessage.load(ims); | |
UpdateResources(embeddedMessage, imgFileName); | |
ByteArrayOutputStream outProcessedEmbedded = new ByteArrayOutputStream(); | |
embeddedMessage.save(outProcessedEmbedded, SaveOptions.getDefaultMsgUnicode()); | |
//outProcessedEmbedded.reset(); | |
ByteArrayInputStream inProcessedEmbedded = new ByteArrayInputStream(outProcessedEmbedded.toByteArray()); | |
msg.getAttachments().get_Item(i).setContentStream(inProcessedEmbedded); | |
} | |
} | |
for (LinkedResource att : msg.getLinkedResources()) | |
{ | |
if (att.getContentType().getMediaType() == "image/jpg") | |
{ | |
try { | |
File embeddedFile = new File(imgFileName); | |
FileInputStream es = null; | |
es = new FileInputStream(embeddedFile); | |
att.setContentStream(es ); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create a new message | |
MailMessage message = new MailMessage(); | |
message.setFrom(new MailAddress("sender@gmail.com")); | |
message.getTo().add("receiver@gmail.com"); | |
message.setSubject("Using MailMessage Features"); | |
// Specify message date | |
message.setDate(new Date()); | |
// Specify message priority | |
message.setPriority(MailPriority.High); | |
// Specify message sensitivity | |
message.setSensitivity(MailSensitivity.Normal); | |
// Specify options for delivery notifications | |
message.setDeliveryNotificationOptions(DeliveryNotificationOptions.OnSuccess); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient _client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
//Create ExchangeMailboxInfo instance to save default mailbox info | |
ExchangeMailboxInfo mailbox = _client.getMailboxInfo(); | |
//Declare ExchangeMessageInfoCollection instance for storing messages info collection | |
ExchangeMessageInfoCollection messages = null; | |
//Declare variable for getting specified custom folder URI | |
ExchangeFolderInfo subfolderInfo[] = new ExchangeFolderInfo[] { null }; | |
//Check if specified custom folder exists | |
//PROBLEM: at this line | |
_client.folderExists(mailbox.getInboxUri(), "592633", subfolderInfo); | |
if (subfolderInfo != null) { | |
//Get all the messages info from the target URI | |
messages = _client.findMessages(subfolderInfo[0].getUri()); | |
//Parse all the messages info collection | |
for (ExchangeMessageInfo info : messages) { | |
String strMessageURI = info.getUniqueUri(); | |
// now get the message details using FetchMessage() | |
MailMessage msg = _client.fetchMessage(strMessageURI); | |
// display message details | |
System.out.println("Subject: " + msg.getSubject()); | |
} | |
} /*else { | |
System.out.println("Target folder not found"); | |
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
//Initialize MapiContact object and populate contact information | |
MapiContact contact = new MapiContact(); | |
contact.setElectronicAddresses(null); | |
contact.setTelephones(null); | |
contact.setNameInfo(new MapiContactNamePropertySet("John", "", "Doe")); | |
//Create the contact on the Exchange server | |
client.createContact(contact); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
String username = "test.exchange"; | |
String password = "pwd"; | |
String domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials); | |
//Create New Contact | |
Contact contact = new Contact(); | |
//Set general info | |
contact.setGender(Gender.Male); | |
contact.setDisplayName("Frank Lin"); | |
contact.setCompanyName("ABC Co."); | |
contact.setJobTitle("Executive Manager"); | |
//Add Phone numbers | |
PhoneNumber phoneNumber = new PhoneNumber(); | |
phoneNumber.setNumber("123456789"); | |
phoneNumber.setCategory(PhoneNumberCategory.getHome()); | |
contact.getPhoneNumbers().add(phoneNumber); | |
//contact's associated persons | |
AssociatedPerson person = new AssociatedPerson(); | |
person.setName("Catherine"); | |
person.setCategory(AssociatedPersonCategory.getSpouse()); | |
contact.getAssociatedPersons().add(person); | |
person = new AssociatedPerson(); | |
person.setName("Bob"); | |
person.setCategory(AssociatedPersonCategory.getChild()); | |
contact.getAssociatedPersons().add(person); | |
person = new AssociatedPerson(); | |
person.setName("Merry"); | |
person.setCategory(AssociatedPersonCategory.getSister()); | |
contact.getAssociatedPersons().add(person); | |
//URLs | |
Url url = new Url(); | |
url.setCategory(UrlCategory.getBlog()); | |
url.setHref("www.blog.com"); | |
contact.getUrls().add(url); | |
url = new Url(); | |
url.setCategory(UrlCategory.getHomePage()); | |
url.setHref("www.homepage.com"); | |
contact.getUrls().add(url); | |
//Set contact's Email address | |
EmailAddress address = new EmailAddress(); | |
address.setAddress("Frank.Lin@Abc.com"); | |
address.setDisplayName("Frank Lin"); | |
address.setCategory(EmailAddressCategory.getCustom().getEmail1()); | |
try | |
{ | |
client.createContact(contact); | |
} | |
catch (Exception ex) | |
{ | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = null; | |
try { | |
client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password"); | |
Calendar calendar = Calendar.getInstance(); | |
Date startTime = calendar.getTime(); | |
calendar.add(java.util.Calendar.HOUR, 1); | |
Date endTime = calendar.getTime(); | |
String timeZone = "America/New_York"; | |
Appointment appointment = new Appointment("Room 121", startTime, endTime, | |
MailAddress.to_MailAddress("email1@aspose.com"), | |
MailAddressCollection.to_MailAddressCollection("email2@aspose.com")); | |
appointment.setTimeZone(timeZone); | |
appointment.setSummary("EMAILNET-35198 - ".concat(java.util.UUID.randomUUID().toString())); | |
appointment.setDescription("EMAILNET-35198 Ability to add Java event to Secondary Calendar of Office 365"); | |
// Create new calendar folder | |
client.createFolder(client.getMailboxInfo().getCalendarUri(), "new calendar", null, "IPF.Appointment"); | |
ExchangeFolderInfoCollection calendarSubFolders = client.listSubFolders(client.getMailboxInfo().getCalendarUri()); | |
String newCalendarFolderUri = calendarSubFolders.get_Item(0).getUri(); | |
// Appointment API with calendar folder URI | |
// Create Appointment | |
client.createAppointment(appointment, newCalendarFolderUri); | |
// Update Appointment | |
appointment.setLocation("Room 122"); | |
client.updateAppointment(appointment, newCalendarFolderUri); | |
// List Appointments | |
Appointment[] listAppointments = client.listAppointments(newCalendarFolderUri); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment, newCalendarFolderUri); | |
listAppointments = client.listAppointments(newCalendarFolderUri); | |
// Appointment API with context current calendar folder URI | |
client.setCurrentCalendarFolderUri(newCalendarFolderUri); | |
// Create Appointment | |
client.createAppointment(appointment); | |
appointment.setLocation("Room 122"); | |
// Update Appointment | |
client.updateAppointment(appointment); | |
// List Appointments | |
listAppointments = client.listAppointments(); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment); | |
listAppointments = client.listAppointments(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com/ews/Exchange.asmx", "username", "password", ""); | |
client.addHeader("X-AnchorMailbox", "username@domain.com"); | |
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by providing credentials | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
ExchangeFolderInfo info = client.getFolderInfo(mailboxInfo.getInboxUri()); | |
ExchangeFolderInfoCollection fc = new ExchangeFolderInfoCollection(); | |
fc.addItem(info); | |
client.backup(fc, "Backup.pst", 0); //0 for None, 1 for Recursive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
// Create an appointment | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addItem(new MailAddress("attendee_address@aspose.com", "Attendee")); | |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); | |
String strStartTime = "02-04-2013 11:30:00"; | |
Date startTime = dateformat.parse(strStartTime); | |
String strEndTime = "02-04-2013 12:30:00"; | |
Date endTime = dateformat.parse(strEndTime); | |
Appointment app = new Appointment("Room 112", startTime, endTime, new MailAddress("organizeraspose-email.test3@domain.com"), attendees); | |
app.setTimeZone("GMT"); | |
String uid = client.createAppointment(app); | |
// Update an appointment | |
Appointment fetchedAppointment1 = client.fetchAppointment(uid); | |
app.setLocation("Room 115"); | |
app.setSummary("New summary for " + app.getSummary()); | |
app.setDescription("New Description"); | |
client.updateAppointment(app); | |
Appointment[] appointments1 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments1.length); | |
// Delete/Cancel an appointment | |
Appointment fetchedAppointment2 = client.fetchAppointment(uid); | |
System.out.println("Summary: " + fetchedAppointment2.getSummary()); | |
System.out.println("Location: " + fetchedAppointment2.getLocation()); | |
System.out.println("Description: " + fetchedAppointment2.getDescription()); | |
client.cancelAppointment(app); | |
Appointment[] appointments2 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments2.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static IEWSClient getEWSClient() { | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static ExchangeClient getExchangeClient() { | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "Username", "password", "domain"); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Connect to Exchange Server using ImapClient class | |
ImapClient imapClient = new ImapClient("imap.gmail.com", 993, "username", "password"); | |
// Select the Inbox folder | |
imapClient.selectFolder(ImapFolderInfo.IN_BOX); | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.listMessages(); | |
for (ImapMessageInfo msgInfo : msgCollection) { | |
System.out.println(msgInfo.getSubject()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient imapClient = new ImapClient("imap.gmail.com", 993, "username", "password"); | |
imapClient.selectFolder(ImapFolderInfo.IN_BOX); | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.listMessages(); | |
for (ImapMessageInfo msgInfo : msgCollection) { | |
//Fetch the message from Inbox using its SequenceNumber from msgInfo | |
MailMessage msg = imapClient.fetchMessage(msgInfo.getSequenceNumber()); | |
//Save the message to disc now | |
msg.save(dataDir + msgInfo.getSequenceNumber() + ".msg", SaveOptions.getDefaultMsgUnicode()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34997 - ", "EMAILNET-34997 Exchange: Copy a message and get reference to the new Copy item"); | |
String messageUri = client.appendMessage(message); | |
String newMessageUri = client.copyItem(messageUri, client.getMailboxInfo().getDeletedItemsUri()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exhcnage server uri", "Username", "Password", "domain"); | |
try { | |
String inbox = client.getMailboxInfo().getInboxUri(); | |
String folderName1 = "EMAILNET-35054"; | |
String subFolderName0 = "2015"; | |
String folderName2 = folderName1 + "/" + subFolderName0; | |
ExchangeFolderInfo rootFolderInfo = null; | |
ExchangeFolderInfo folderInfo = null; | |
try { | |
client.setUseSlashAsFolderSeparator(true); | |
client.createFolder(client.getMailboxInfo().getInboxUri(), folderName1); | |
client.createFolder(client.getMailboxInfo().getInboxUri(), folderName2); | |
} finally { | |
ExchangeFolderInfo subfolderInfo[] = new ExchangeFolderInfo[] { null }; | |
boolean outRefCondition2 = client.folderExists(inbox, folderName1, subfolderInfo); | |
rootFolderInfo = subfolderInfo[0]; | |
if (outRefCondition2) { | |
ExchangeFolderInfo[] referenceToFolderInfo = { folderInfo }; | |
boolean outRefCondition3 = client.folderExists(inbox, folderName2, /*out*/ referenceToFolderInfo); | |
folderInfo = referenceToFolderInfo[0]; | |
if (outRefCondition3) { | |
client.deleteFolder(folderInfo.getUri(), true); | |
client.deleteFolder(rootFolderInfo.getUri(), true); | |
} | |
} | |
} | |
} finally { | |
if (client != null) | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.aspose.com/ews/Exchange.asmx", "user1", "password", ""); | |
MailMessage message = new MailMessage("user1@domain.com", "user2@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.send(message); | |
try { | |
Thread.sleep(50000); | |
} catch (InterruptedException ex) { | |
Thread.currentThread().interrupt(); | |
} | |
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
if (messageInfoCol.size() == 1) | |
System.out.println("1 message in Inbox"); | |
else | |
System.out.println("Error! No message in Inbox"); | |
MailMessage message1 = new MailMessage("user1@domain.com", "user2@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.send(message1); | |
try { | |
Thread.sleep(50000); | |
} catch (InterruptedException ex) { | |
Thread.currentThread().interrupt(); | |
} | |
// Wait for a while | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
if (messageInfoCol.size() == 2) | |
System.out.println("2 messages in Inbox"); | |
else | |
System.out.println("Error! No new message in Inbox"); | |
MailMessage message2 = new MailMessage("user1@domain.com", "user2@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
message2.getAttachments().addItem(Attachment.createAttachmentFromString("Test attachment 1", "Attachment Name 1")); | |
message2.getAttachments().addItem(Attachment.createAttachmentFromString("Test attachment 2", "Attachment Name 2")); | |
client.reply(message2, messageInfoCol.get_Item(0)); | |
client.replyAll(message2, messageInfoCol.get_Item(0)); | |
client.forward(message2, messageInfoCol.get_Item(0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
String strContactToDelete = "John Teddy"; | |
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri()); | |
for (Contact contact : contacts) { | |
if (contact.getDisplayName().equals(strContactToDelete)) | |
client.deleteContact(contact); | |
} | |
client.dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeClient client = new ExchangeClient("http://ex2003/exchange/administrator", "username", "password", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
// List all messages from Inbox folder | |
System.out.println("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(mailboxInfo.getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Delete message based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("delete") == true) { | |
// Delete it | |
client.deleteMessage(msgInfo.getUniqueUri()); | |
System.out.println("Message deleted...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
// List all messages from Inbox folder | |
System.out.println("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(mailboxInfo.getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Delete message based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("delete") == true) { | |
// Delete it | |
client.deleteMessage(msgInfo.getUniqueUri()); | |
System.out.println("Message deleted...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.add("address4@host.com"); | |
newMembers.add("address5@host.com"); | |
client.addToDistributionList(distributionLists[0], newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.setId("list's id"); | |
distributionList.setChangeKey("list's change key"); | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.add("address6@host.com"); | |
client.addToDistributionList(distributionList, newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
String id = distributionLists[0].getId(); | |
MailAddress distributionListAddress = new MailAddress("privateDL", true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.setDisplayName("test private list"); | |
MailAddressCollection members = new MailAddressCollection(); | |
members.add("address1@host.com"); | |
members.add("address2@host.com"); | |
members.add("address3@host.com"); | |
client.createDistributionList(distributionList, members); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
MailAddressCollection members = client.fetchDistributionList(distributionLists[0]); | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.addItem(members.get_Item(0)); | |
membersToDelete.addItem(members.get_Item(1)); | |
client.deleteFromDistributionList(distributionLists[0], membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.setId("list's id"); | |
distributionList.setChangeKey("list's change key"); | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
MailAddress addressToDelete = new MailAddress("address", true); | |
membersToDelete.addItem(addressToDelete); | |
client.addToDistributionList(distributionList, membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
client.deleteDistributionList(distributionLists[0], true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.setId("list's id"); | |
client.deleteDistributionList(distributionList, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
MailAddressCollection members = client.expandDistributionList(new MailAddress("public.distribution.list@host.com")); | |
for (MailAddress member : members) { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
for (ExchangeDistributionList distributionList : distributionLists) { | |
MailAddressCollection members = client.fetchDistributionList(distributionList); | |
for (MailAddress member : members) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx/", "user", "password", ""); | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
MailAddress distributionListAddress = distributionLists[0].toMailAddress(); | |
MailMessage message = new MailMessage(new MailAddress("from@host.com"), distributionListAddress); | |
message.setSubject("sendToPrivateDistributionList"); | |
client.send(message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static String username = "administrator"; | |
public static String password = "pwd"; | |
public static String domain = "ex2010.local"; | |
public static void main(String[] args) { | |
recursiveMessages(); | |
} | |
public static void recursiveMessages() { | |
//Download Messages from Exchange Server Folders and Subfolders Recursively | |
try { | |
String rootFolder = domain + "-" + username; | |
createDirectory(rootFolder); | |
String inboxFolder = rootFolder + "\\Inbox"; | |
createDirectory(inboxFolder); | |
System.out.println("Downloading all messages from Inbox...."); | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", username, password, domain); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
System.out.println("Mailbox URI: " + mailboxInfo.getMailboxUri()); | |
String rootUri = client.getMailboxInfo().getRootUri(); | |
// List all the folders from Exchange server | |
ExchangeFolderInfoCollection folderInfoCollection = client.listSubFolders(rootUri); | |
for (ExchangeFolderInfo folderInfo : folderInfoCollection) { | |
// Call the recursive method to read messages and get sub-folders | |
listMessagesInFolder(client, folderInfo, rootFolder); | |
} | |
System.out.println("All messages downloaded."); | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} | |
} | |
private static void listMessagesInFolder(IEWSClient client, ExchangeFolderInfo folderInfo, String rootFolder) { | |
// Create the folder in disk (same name as on IMAP server) | |
String currentFolder = rootFolder + "\\" + folderInfo.getDisplayName(); | |
createDirectory(currentFolder); | |
// List messages | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(folderInfo.getUri()); | |
System.out.println("Listing messages...."); | |
int i = 0; | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Get subject and other properties of the message | |
System.out.println("Subject: " + msgInfo.getSubject()); | |
// Get rid of characters like ? and :, which should not be included in a file name | |
String fileName = msgInfo.getSubject().replace(":", " ").replace("?", " "); | |
// Save the message in MSG format | |
MailMessage msg = client.fetchMessage(msgInfo.getUniqueUri()); | |
//msg.save(currentFolder + "\\" + fileName + "-" + i + ".msg", MailMessageSaveType.getOutlookMessageFormatUnicode()); | |
msg.save(currentFolder + "\\" + fileName + "-" + i + ".msg", SaveOptions.getDefaultMsgUnicode()); | |
i++; | |
} | |
System.out.println("============================\n"); | |
try { | |
// If this folder has sub-folders, call this method recursively to get messages | |
ExchangeFolderInfoCollection folderInfoCollection = client.listSubFolders(folderInfo.getUri()); | |
for (ExchangeFolderInfo subfolderInfo : folderInfoCollection) { | |
listMessagesInFolder(client, subfolderInfo, currentFolder); | |
} | |
} catch (Exception ex) { | |
} | |
} | |
public static void createDirectory(String directoryName) { | |
File theDir = new File(directoryName); | |
// if the directory does not exist, create it | |
if (!theDir.exists()) { | |
System.out.println("creating directory: " + directoryName); | |
boolean result = false; | |
try { | |
theDir.mkdir(); | |
result = true; | |
} catch (SecurityException se) { | |
//handle it | |
} | |
if (result) { | |
System.out.println("DIR created"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void main(String[] args) { | |
downloadMessagesFromPublicFolders(); | |
} | |
public static void downloadMessagesFromPublicFolders() { | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeFolderInfoCollection folders = client.listPublicFolders(); | |
for (ExchangeFolderInfo publicFolder : folders) { | |
System.out.println("Name: " + publicFolder.getDisplayName()); | |
System.out.println("Subfolders count: " + publicFolder.getChildFolderCount()); | |
listMessagesFromSubFolder(publicFolder, client); | |
} | |
} | |
private static void listMessagesFromSubFolder(ExchangeFolderInfo publicFolder, IEWSClient client) { | |
System.out.println("Folder Name: " + publicFolder.getDisplayName()); | |
ExchangeMessageInfoCollection msgInfoCollection = client.listMessagesFromPublicFolder(publicFolder); | |
for (ExchangeMessageInfo messageInfo : msgInfoCollection) { | |
MailMessage msg = client.fetchMessage(messageInfo.getUniqueUri()); | |
System.out.println(msg.getSubject()); | |
msg.save(msg.getSubject() + ".msg", SaveOptions.getDefaultMsgUnicode()); | |
} | |
// Call this method recursively for any subfolders | |
if (publicFolder.getChildFolderCount() > 0) { | |
ExchangeFolderInfoCollection folderInfoColl = client.listSubFolders(publicFolder); | |
for (ExchangeFolderInfo folderInfo : folderInfoColl) { | |
listMessagesFromSubFolder(folderInfo, client); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = null; | |
try { | |
client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password"); | |
Calendar calendar = Calendar.getInstance(); | |
Date startTime = calendar.getTime(); | |
calendar.add(java.util.Calendar.HOUR, 1); | |
Date endTime = calendar.getTime(); | |
String timeZone = "America/New_York"; | |
Appointment appointment = new Appointment("Room 121", startTime, endTime, | |
MailAddress.to_MailAddress("email1@aspose.com"), | |
MailAddressCollection.to_MailAddressCollection("email2@aspose.com")); | |
appointment.setTimeZone(timeZone); | |
appointment.setSummary("EMAILNET-35198 - ".concat(java.util.UUID.randomUUID().toString())); | |
appointment.setDescription("EMAILNET-35198 Ability to add Java event to Secondary Calendar of Office 365"); | |
// Create new calendar folder | |
client.createFolder(client.getMailboxInfo().getCalendarUri(), "new calendar", null, "IPF.Appointment"); | |
ExchangeFolderInfoCollection calendarSubFolders = client.listSubFolders(client.getMailboxInfo().getCalendarUri()); | |
String newCalendarFolderUri = calendarSubFolders.get_Item(0).getUri(); | |
// Appointment API with calendar folder URI | |
// Create Appointment | |
client.createAppointment(appointment, newCalendarFolderUri); | |
// Update Appointment | |
appointment.setLocation("Room 122"); | |
client.updateAppointment(appointment, newCalendarFolderUri); | |
// List Appointments | |
Appointment[] listAppointments = client.listAppointments(newCalendarFolderUri); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment, newCalendarFolderUri); | |
listAppointments = client.listAppointments(newCalendarFolderUri); | |
// Appointment API with context current calendar folder URI | |
client.setCurrentCalendarFolderUri(newCalendarFolderUri); | |
// Create Appointment | |
client.createAppointment(appointment); | |
appointment.setLocation("Room 122"); | |
// Update Appointment | |
client.updateAppointment(appointment); | |
// List Appointments | |
listAppointments = client.listAppointments(); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment); | |
listAppointments = client.listAppointments(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.password"); | |
Calendar date = Calendar.getInstance(); | |
Calendar startTime = Calendar.getInstance(); | |
startTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY), 0, 0); | |
Calendar endTime = Calendar.getInstance(); | |
endTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY) + 1, 0, 0); | |
String timeZone = "America/New_York"; | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addMailAddress(new MailAddress("attendee_address@aspose.com", "Attendee")); | |
Appointment app = new Appointment("Room 112", startTime.getTime(), endTime.getTime(), new MailAddress("organizeraspose-email.test3@domain.com"), attendees); | |
app.setTimeZone(timeZone); | |
app.setSummary("NETWORKNET-34136" + UUID.randomUUID().toString()); | |
app.setDescription("NETWORKNET-34136 Exchange 2007/EWS: Provide support for Add/Update/Delete calendar items"); | |
String uid = client.createAppointment(app); | |
Appointment fetchedAppointment1 = client.fetchAppointment(uid); | |
app.setLocation("Room 115"); | |
app.setSummary("New summary for " + app.getSummary()); | |
app.setDescription("New Description"); | |
client.updateAppointment(app); | |
Appointment[] appointments1 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments1.length); | |
Appointment fetchedAppointment2 = client.fetchAppointment(uid); | |
System.out.println("Summary: " + fetchedAppointment2.getSummary()); | |
System.out.println("Location: " + fetchedAppointment2.getLocation()); | |
System.out.println("Description: " + fetchedAppointment2.getDescription()); | |
client.cancelAppointment(app); | |
Appointment[] appointments2 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments2.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
//Define total number of items per page | |
int itemsPerPage = 2; | |
List<AppointmentPageInfo> pages = new List<AppointmentPageInfo>(); | |
AppointmentPageInfo pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage); | |
pages.addItem(pagedAppointmentCol); | |
while (!pagedAppointmentCol.getLastPage()) | |
{ | |
pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage, pagedAppointmentCol.getPageOffset() + 1); | |
pages.addItem(pagedAppointmentCol); | |
} | |
//Verify the number of appointments retrieved using the paging support | |
int retrievedItems = 0; | |
for (AppointmentPageInfo folderCol : (Iterable<AppointmentPageInfo>) pages) | |
retrievedItems += folderCol.getItems().size(); | |
System.out.println("Total items retrieved: " + retrievedItems); | |
} finally { | |
if (client != null) | |
((IDisposable)client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// delegate calendar access permission | |
ExchangeDelegateUser delegateUser = new ExchangeDelegateUser("sharingfrom@domain.com", ExchangeDelegateFolderPermissionLevel.NotSpecified); | |
delegateUser.getFolderPermissions().setCalendarFolderPermissionLevel(ExchangeDelegateFolderPermissionLevel.Reviewer); | |
client.delegateAccess(delegateUser, "sharingfrom@domain.com"); | |
// Create invitation | |
MapiMessage mapiMessage = client.createCalendarSharingInvitationMessage("sharingfrom@domain.com"); | |
MailConversionOptions options = new MailConversionOptions(); | |
options.setConvertAsTnef(true); | |
MailMessage mail = mapiMessage.toMailMessage(options); | |
client.send(mail); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
try { | |
String domain = "litwareinc.com"; | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create the meeting request | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
Date startDate = sdf.parse("10/05/2015 10:00:00"); | |
Date endDate = sdf.parse("10/05/2015 10:30:00"); | |
MailAddressCollection coll = new MailAddressCollection(); | |
coll.add("bob@" + domain); | |
Appointment app = new Appointment("meeting request", startDate, endDate, new MailAddress("administrator@" + domain), coll); | |
app.setSummary("meeting request summary"); | |
app.setDescription("description"); | |
// Create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("administrator@" + domain)); | |
msg.setTo(coll); | |
msg.isBodyHtml(true); | |
msg.setHtmlBody("<h3>HTML Heading</h3><p>Email Message detail</p>"); | |
msg.setSubject("meeting request"); | |
msg.addAlternateView(app.requestApointment(0)); | |
// Send the appointment | |
client.send(msg); | |
System.out.println("Appointment request sent"); | |
} catch (ExchangeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client1 = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser1", "pwd", "domain"); | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client2 = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser2", "pwd", "domain"); | |
String folder = "Drafts"; | |
try { | |
for (ExchangeMessageInfo messageInfo : client1.listMessages(folder)) | |
client1.deleteMessage(messageInfo.getUniqueUri()); | |
String subj1 = String.format("NETWORKNET_33354 {0} {1}", "User", "User1"); | |
client1.appendMessage(folder, new MailMessage("User1@exchange.conholdate.local", "To@aspsoe.com", subj1, "")); | |
for (ExchangeMessageInfo messageInfo : client2.listMessages(folder)) | |
client2.deleteMessage(messageInfo.getUniqueUri()); | |
String subj2 = String.format("NETWORKNET_33354 {0} {1}", "User", "User2"); | |
client2.appendMessage(folder, new MailMessage("User2@exchange.conholdate.local", "To@aspose.com", subj2, "")); | |
ExchangeMessageInfoCollection messInfoColl = client1.listMessages(folder); | |
System.out.println((messInfoColl.size() == 1) ? "success" : "failure"); | |
System.out.println((messInfoColl.get_Item(0).getSubject() == subj1) ? "success" : "failure"); | |
client1.impersonateUser(0, "User2@exchange.conholdate.local");/* | |
* PrimarySmtpAddress = | |
* 0,PrincipalName = | |
* 1,SID = 2,SmtpAddress | |
* = 3, | |
*/ | |
ExchangeMessageInfoCollection messInfoColl1 = client1.listMessages(folder); | |
System.out.println((messInfoColl1.size() == 1) ? "success" : "failure"); | |
System.out.println((messInfoColl1.get_Item(0).getSubject() == subj2) ? "success" : "failure"); | |
client1.resetImpersonation(); | |
ExchangeMessageInfoCollection messInfoColl2 = client1.listMessages(folder); | |
System.out.println((messInfoColl2.size() == 1) ? "success" : "failure"); | |
System.out.println((messInfoColl1.get_Item(0).getSubject() == subj1) ? "success" : "failure"); | |
} finally { | |
try { | |
for (ExchangeMessageInfo messageInfo : client1.listMessages(folder)) | |
client1.deleteMessage(messageInfo.getUniqueUri()); | |
for (ExchangeMessageInfo messageInfo : client2.listMessages(folder)) | |
client2.deleteMessage(messageInfo.getUniqueUri()); | |
} catch (Exception ex) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
// Number of items per page | |
int itemsPerPage = 5; | |
// Create a storage list | |
List<ExchangeMessagePageInfo> pages = new List<ExchangeMessagePageInfo>(); | |
ExchangeMessagePageInfo pageInfo = client.listMessagesByPage(client.getMailboxInfo().getInboxUri(), itemsPerPage); | |
pages.addItem(pageInfo); | |
// Retrieve further pages | |
while (!pageInfo.getLastPage()) { | |
pageInfo = client.listMessagesByPage(client.getMailboxInfo().getInboxUri(), itemsPerPage, pageInfo.getPageOffset() + 1); | |
pages.addItem(pageInfo); | |
} | |
// Verify the number of items retrieved | |
int retrievedItems = 0; | |
for (ExchangeMessagePageInfo pageCol : (Iterable<ExchangeMessagePageInfo>) pages) | |
retrievedItems += pageCol.getItems().size(); | |
System.out.println("Items retrieved: " + retrievedItems); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage msg = client.fetchMessage(strMessageURI); | |
// Display message details | |
System.out.println("Subject: " + msg.getSubject()); | |
System.out.println("HTML Body: " + msg.getHtmlBody()); | |
System.out.println("Number of attachments: " + msg.getAttachments().size()); | |
for (Attachment att : msg.getAttachments()) { | |
System.out.println("Attachment Name: " + att.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage msg = client.fetchMessage(strMessageURI); | |
// Display message details | |
System.out.println("Subject: " + msg.getSubject()); | |
//Console.WriteLine("HTML Body: " + msg.HtmlBody); | |
// How many attachments | |
System.out.println("Number of attachments: " + msg.getAttachments().size()); | |
// List the attachments | |
for (Attachment att : msg.getAttachments()) { | |
System.out.println("Attachment Name: " + att.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Emails from specific host | |
builder.getFrom().contains("SpecificHost.com"); | |
// AND all emails that arrived before today | |
builder.getInternalDate().before(new Date()); | |
// AND all emails that arrived since 7 days ago | |
builder.getInternalDate().since(new Date(new Date().getTime() + TimeUnit.DAYS.toDays(-7))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Specify OR condition | |
builder.or(builder.getSubject().contains("test"), builder.getFrom().contains("noreply@host.com")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "username", "password", "domain"); | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
// Query building by means of ExchangeQueryBuilder class | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
// Subject contains "Newsletter" | |
builder.getSubject().contains("Newsletter"); | |
// Emails that arrived today | |
try { | |
builder.getInternalDate().on(sdf.parse("10/05/2016 10:00:00")); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
// Build the query | |
MailQuery query = builder.getQuery(); | |
// Get list of messages | |
ExchangeMessageInfoCollection messages = client.listMessages(client.getMailboxInfo().getInboxUri(), query, false); | |
System.out.println("Imap: " + messages.size() + " message(s) found."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
//IgnoreCase is True | |
MailQueryBuilder builder1 = new MailQueryBuilder(); | |
builder1.getFrom().contains("tesT", true); | |
MailQuery query1 = builder1.getQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
builder.getInternalDate().beforeOrEqual(new Date()); | |
builder.getInternalDate().since(new Date(new Date().getTime() + TimeUnit.DAYS.toDays(1))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails from specific domain | |
builder.getFrom().contains("SpecificHost.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails sent to specific recipient | |
builder.getTo().contains("recipient"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails from specific sender | |
builder.getFrom().contains("saqib.razzaq@127.0.0.1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Emails that arrived today | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
builder.getInternalDate().on(new Date()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
// Query building by means of ExchangeQueryBuilder class | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
// Subject contains "Newsletter" | |
builder.getSubject().contains("Newsletter"); | |
// Emails that arrived today | |
try { | |
builder.getInternalDate().on(sdf.parse("10/05/2016 10:00:00")); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
// Build the query | |
MailQuery query = builder.getQuery(); | |
// Get list of messages | |
ExchangeMessageInfoCollection messages = client.listMessages(client.getMailboxInfo().getInboxUri(), query, false); | |
System.out.println("Imap: " + messages.size() + " message(s) found."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeQueryBuilder queryBuilder = null; | |
MailQuery query = null; | |
ExchangeTask fetchedTask = null; | |
ExchangeMessageInfoCollection messageInfoCol = null; | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
//Set timezone for tasks | |
client.setTimezoneId("Central Europe Standard Time"); | |
//We use these status values for specifying in queries | |
Integer[] values = new Integer[] {ExchangeTaskStatus.Completed, ExchangeTaskStatus.Deferred, | |
ExchangeTaskStatus.InProgress, ExchangeTaskStatus.NotStarted, ExchangeTaskStatus.WaitingOnOthers}; | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
//Now retrieve the tasks with specific statuses | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().equals(status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
fetchedTask = client.fetchTask(messageInfoCol.get_Item(0).getUniqueUri()); | |
} | |
//retrieve all other than specified | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notEquals((int)status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
} | |
//specifying multiple criterion | |
Integer[] selectedStatuses = new Integer[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().in(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
//list all those which are not in our specified statuses | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notIn(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = createEWSClient(); | |
ContactQueryBuilder queryBuilder = new ContactQueryBuilder(); | |
queryBuilder.getContactDisplayName().contains("testContact"); | |
java.util.Calendar c = java.util.Calendar.getInstance(); | |
c.add(java.util.Calendar.DATE, -1); | |
queryBuilder.getContactCreationTime().greater(c.getTime()); | |
Contact[] findPeople = client.findPeople(client.getMailboxInfo().getContactsUri(), | |
queryBuilder.getQuery(), 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = createEWSClient(); | |
Contact[] findPeople = client.findPeople("smtp", 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
Contact fetchedContact = client.getContact("id"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
// List all the contacts | |
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri()); | |
// Loop through all contacts | |
for (Contact contact : contacts) { | |
// Display name and email address | |
System.out.println("Name: " + contact.getDisplayName() + ", Email Address: " + contact.getEmailAddresses().get_Item(0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
// List all the contacts | |
Contact[] contacts = client.resolveContacts("Changed Name", ExchangeListContactsOptions.FetchAttachmentAndFullPhotoInformation); | |
// Loop through all contacts | |
for (Contact contact : contacts) { | |
// Display name and email address | |
System.out.println("Name: " + contact.getDisplayName() + ", Email Address: " + contact.getEmailAddresses().get_Item(0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
final IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
List<String> ids = new List<String>(); | |
List<MailMessage> messages = new List<MailMessage>(); | |
for (int i = 0; i < 5; i++) { | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", | |
"EMAILNET-35033 - " + UUID.randomUUID().toString(), | |
"EMAILNET-35033 Messages saved from Sent Items folder doesn't contain 'To' field"); | |
messages.addItem(message); | |
String uri = client.appendMessage(message); | |
ids.addItem(uri); | |
} | |
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(ids); | |
for (ExchangeMessageInfo messageInfo : (Iterable<ExchangeMessageInfo>) messageInfoCol) { | |
// Do something ... | |
} | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username", "Username", "password", "domain"); | |
System.out.println("Mailbox size: " + client.getMailboxSize() + " bytes"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
System.out.println("Mailbox URI: " + mailboxInfo.getMailboxUri()); | |
System.out.println("Inbox folder URI: " + mailboxInfo.getInboxUri()); | |
System.out.println("Sent Items URI: " + mailboxInfo.getSentItemsUri()); | |
System.out.println("Drafts folder URI: " + mailboxInfo.getDraftsUri()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.name.com/ews/Exchange.asmx/", "username", "password", ""); | |
System.out.println("Mailbox size: " + client.getMailboxSize() + " bytes"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
System.out.println("Mailbox URI: " + mailboxInfo.getMailboxUri()); | |
System.out.println("Inbox folder URI: " + mailboxInfo.getInboxUri()); | |
System.out.println("Sent Items URI: " + mailboxInfo.getSentItemsUri()); | |
System.out.println("Drafts folder URI: " + mailboxInfo.getDraftsUri()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
System.out.println("Connected to Exchange server..."); | |
// Provide mail tips options | |
// Recipient addresses | |
MailAddressCollection addrColl = new MailAddressCollection(); | |
addrColl.add("test.exchange@ex2010.local"); | |
addrColl.add("invalid.recipient@ex2010.local"); | |
GetMailTipsOptions options = new GetMailTipsOptions(new MailAddress("administrator@ex2010.local"), addrColl, MailTipsType.All); | |
// Get Mail Tips | |
MailTips[] tips = client.getMailTips(options); | |
// Display information about each Mail Tip | |
for (MailTips tip : tips) { | |
// Display Out of office message, if present | |
if (tip.getOutOfOffice() != null) { | |
System.out.println("Out of office: " + tip.getOutOfOffice().getReplyBody().getMessage()); | |
} | |
// Display the invalid email address in recipient, if present | |
if (tip.getInvalidRecipient() == true) { | |
System.out.println("The recipient address is invalid: " + tip.getRecipientAddress()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
UnifiedMessagingConfiguration umConf = client.getUMConfiguration(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void main(String[] args) { | |
listAllFolders(); | |
} | |
private static void listAllFolders() { | |
try { | |
IEWSClient client = EWSClient.getEWSClient("Exchange Server uri", "username", "password", "domain"); | |
System.out.println("Downloading all messages from Inbox...."); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
System.out.println("Mailbox URI: " + mailboxInfo.getMailboxUri()); | |
String rootUri = client.getMailboxInfo().getRootUri(); | |
// List all the folders from Exchange server | |
ExchangeFolderInfoCollection folderInfoCollection = client.listSubFolders(rootUri); | |
for (ExchangeFolderInfo folderInfo : folderInfoCollection) { | |
// Call the recursive method to read messages and get sub-folders | |
listSubFolders(client, folderInfo); | |
} | |
System.out.println("All messages downloaded."); | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} | |
} | |
private static void listSubFolders(IEWSClient client, ExchangeFolderInfo folderInfo) { | |
// Create the folder in disk (same name as on IMAP server) | |
System.out.println(folderInfo.getDisplayName()); | |
try { | |
// If this folder has sub-folders, call this method recursively to get messages | |
ExchangeFolderInfoCollection folderInfoCollection = client.listSubFolders(folderInfo.getUri()); | |
for (ExchangeFolderInfo subfolderInfo : folderInfoCollection) { | |
listSubFolders(client, subfolderInfo); | |
} | |
} catch (Exception ex) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
//Define total number of items per page | |
int itemsPerPage = 2; | |
List<AppointmentPageInfo> pages = new List<AppointmentPageInfo>(); | |
AppointmentPageInfo pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage); | |
pages.addItem(pagedAppointmentCol); | |
while (!pagedAppointmentCol.getLastPage()) | |
{ | |
pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage, pagedAppointmentCol.getPageOffset() + 1); | |
pages.addItem(pagedAppointmentCol); | |
} | |
//Verify the number of appointments retrieved using the paging support | |
int retrievedItems = 0; | |
for (AppointmentPageInfo folderCol : (Iterable<AppointmentPageInfo>) pages) | |
retrievedItems += folderCol.getItems().size(); | |
System.out.println("Total items retrieved: " + retrievedItems); | |
} finally { | |
if (client != null) | |
((IDisposable)client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
final IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
//Items per page | |
int itemsPerPage = 5; | |
ExchangeFolderInfoCollection totalFoldersCollection = client.listSubFolders(client.getMailboxInfo().getRootUri()); | |
List<ExchangeFolderPageInfo> pages = new List<ExchangeFolderPageInfo>(); | |
ExchangeFolderPageInfo pagedFoldersCollection = client.listSubFoldersByPage(client.getMailboxInfo().getRootUri(), itemsPerPage); | |
pages.addItem(pagedFoldersCollection); | |
while (!pagedFoldersCollection.getLastPage()) { | |
pagedFoldersCollection = client.listSubFoldersByPage(client.getMailboxInfo().getRootUri(), itemsPerPage, pagedFoldersCollection.getPageOffset() + 1); | |
pages.addItem(pagedFoldersCollection); | |
} | |
//Verify the items retrieved | |
int retrievedFolders = 0; | |
for (ExchangeFolderPageInfo pageCol : (Iterable<ExchangeFolderPageInfo>) pages) | |
retrievedFolders += pageCol.getItems().size(); | |
System.out.println("Retrieved folders count: " + retrievedFolders); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
String username = "test.exchange"; | |
String password = "pwd"; | |
String domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials); | |
//Listing Tasks from Server | |
client.setTimezoneId("Central Europe Standard Time"); | |
TaskCollection taskCollection = client.listTasks(client.getMailboxInfo().getTasksUri()); | |
//print retrieved tasks' details | |
int iTasksCount = taskCollection.size(); | |
for (int i = 0; i < iTasksCount; i++) { | |
ExchangeTask task = (ExchangeTask) taskCollection.get_Item(i); | |
System.out.println(task.getTimezoneId()); | |
System.out.println(task.getSubject()); | |
System.out.println(task.getStartDate()); | |
System.out.println(task.getDueDate()); | |
} | |
//Listing Tasks from server based on Query - Completed and In-Progress | |
Integer[] selectedStatuses = new Integer[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
ExchangeQueryBuilder queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().in(Arrays.asList(selectedStatuses)); | |
MailQuery query = queryBuilder.getQuery(); | |
taskCollection = client.listTasks(client.getMailboxInfo().getTasksUri(), query); | |
//print retrieved tasks' details | |
iTasksCount = taskCollection.size(); | |
for (int i = 0; i < iTasksCount; i++) { | |
ExchangeTask task = (ExchangeTask) taskCollection.get_Item(i); | |
System.out.println(task.getTimezoneId()); | |
System.out.println(task.getSubject()); | |
System.out.println(task.getStartDate()); | |
System.out.println(task.getDueDate()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to display the basic information | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
System.out.println("Subject: " + msgInfo.getSubject()); | |
System.out.println("From: " + msgInfo.getFrom()); | |
System.out.println("To: " + msgInfo.getTo()); | |
System.out.println("Sent Date: " + msgInfo.getDate()); | |
System.out.println("Read?: " + msgInfo.isRead()); | |
System.out.println("Message ID: " + msgInfo.getMessageId()); | |
System.out.println("Unique URI: " + msgInfo.getUniqueUri()); | |
System.out.println("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.aspose.com/ews/Exchange.asmx/", "aspose-email.test3", "mahlakaaspose", ""); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to display the basic information | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
System.out.println("Subject: " + msgInfo.getSubject()); | |
System.out.println("From: " + msgInfo.getFrom()); | |
System.out.println("To: " + msgInfo.getTo()); | |
System.out.println("Sent Date: " + msgInfo.getDate()); | |
System.out.println("Read?: " + msgInfo.isRead()); | |
System.out.println("Message ID: " + msgInfo.getMessageId()); | |
System.out.println("Unique URI: " + msgInfo.getUniqueUri()); | |
System.out.println("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username","username", "password", "domain"); | |
// Get folder URI | |
String strFolderURI = ""; | |
strFolderURI = client.getMailboxInfo().getInboxUri(); | |
strFolderURI = client.getMailboxInfo().getDeletedItemsUri(); | |
strFolderURI = client.getMailboxInfo().getDraftsUri(); | |
strFolderURI = client.getMailboxInfo().getSentItemsUri(); | |
// Get list of messages from the specified folder | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(strFolderURI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get folder URI | |
String strFolderURI = ""; | |
strFolderURI = client.getMailboxInfo().getInboxUri(); | |
strFolderURI = client.getMailboxInfo().getDeletedItemsUri(); | |
strFolderURI = client.getMailboxInfo().getDraftsUri(); | |
strFolderURI = client.getMailboxInfo().getSentItemsUri(); | |
// Get list of messages from the specified folder | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(strFolderURI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to copy | |
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri()); | |
for(ExchangeConversation conversation : conversations) { | |
// Display topic | |
System.out.println("Topic: " + conversation.getConversationTopic()); | |
// Copy the conversation item based on some condition | |
if (conversation.getConversationTopic().contains("test email") == true) { | |
client.copyConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri()); | |
System.out.println("Copied the conversation item to another folder"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to delete | |
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeConversation conversation : conversations) { | |
// Display topic | |
System.out.println("Topic: " + conversation.getConversationTopic()); | |
// Delete the conversation item based on some condition | |
if (conversation.getConversationTopic().contains("test email") == true) | |
{ | |
client.deleteConversationItems(conversation.getConversationId()); | |
System.out.println("Deleted the conversation item"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Find Conversation Items in the Inbox folder | |
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri()); | |
// Show all conversations | |
for (ExchangeConversation conversation : conversations) { | |
// Display conversation properties like Id and Topic | |
System.out.println("Topic: " + conversation.getConversationTopic()); | |
System.out.println("Flag Status: " + conversation.getFlagStatus()); | |
System.out.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to move | |
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeConversation conversation : conversations) { | |
// Display topic | |
System.out.println("Topic: " + conversation.getConversationTopic()); | |
// Move the conversation item based on some condition | |
if (conversation.getConversationTopic().contains("test email") == true) | |
{ | |
client.moveConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri()); | |
System.out.println("Moved the conversation item to another folder"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = getAsposeEWSClient(); | |
System.out.println("Connected to Exchange server"); | |
InboxRule rule = new InboxRule(); | |
rule.setDisplayName("Message from client ABC"); | |
// Add conditions | |
RulePredicates newRules = new RulePredicates(); | |
// Subject contains string "ABC" | |
newRules.containsSubjectStrings().addItem("ABC"); | |
// From address is administrator@ex2010.local | |
newRules.getFromAddresses().add("administrator@ex2010.local"); | |
// Add the conditions | |
rule.setConditions(newRules); | |
// Add Actions | |
RuleActions newActions = new RuleActions(); | |
// Move the message to a folder | |
newActions.setMoveToFolder("120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="); | |
// Add the actions | |
rule.setActions(newActions); | |
client.createInboxRule(rule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
private static IEWSClient getAsposeEWSClient() { | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Return the instance of IEWSClient class | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = getAsposeEWSClient(); | |
System.out.println("Connected to Exchange server"); | |
// Get all Inbox Rules | |
InboxRule[] inboxRules = client.getInboxRules(); | |
// Display information about each rule | |
for (InboxRule inboxRule : inboxRules) { | |
// Display name of the rule | |
System.out.println("Display Name: " + inboxRule.getDisplayName()); | |
// Conditions included in this rule | |
System.out.println("Conditions: "); | |
// Check if there is a "From Address" condition | |
if (inboxRule.getConditions().getFromAddresses().size() > 0) { | |
for (MailAddress fromAddress : inboxRule.getConditions().getFromAddresses()) { | |
System.out.println("From: " + fromAddress.getDisplayName() + " - " + fromAddress.getAddress()); | |
} | |
} | |
// Check if there is a "Subject Contains" condition | |
if (inboxRule.getConditions().containsSubjectStrings().size() > 0) { | |
for (String subject : inboxRule.getConditions().containsSubjectStrings()) { | |
System.out.println("Subject contains: " + subject); | |
} | |
} | |
// Actions included in this rule | |
System.out.println("Actions: "); | |
// Check if there is a "Move to Folder" action | |
if (inboxRule.getActions().getMoveToFolder().length() > 0) { | |
System.out.println("Move message to folder: " + inboxRule.getActions().getMoveToFolder()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = getAsposeEWSClient(); | |
System.out.println("Connected to Exchange server"); | |
// Get all Inbox Rules | |
InboxRule[] inboxRules = client.getInboxRules(); | |
// Loop through each rule | |
for (InboxRule inboxRule : inboxRules) { | |
// Display name of the rule | |
System.out.println("Display Name: " + inboxRule.getDisplayName()); | |
if (inboxRule.getDisplayName() == "Message from client ABC") { | |
System.out.println("Updating the rule...."); | |
// Add a new condition. From address | |
inboxRule.getConditions().getFromAddresses().set_Item(0, new MailAddress("administrator@ex2010.local", true)); | |
client.updateInboxRule(inboxRule); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Create the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri()); | |
UserConfiguration userConfig = new UserConfiguration(userConfigName); | |
userConfig.getDictionary().put("key1", "value1"); | |
userConfig.getDictionary().put("key2", "value2"); | |
userConfig.getDictionary().put("key3", "value3"); | |
client.createUserConfiguration(userConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Delete User Configuration | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri()); | |
client.deleteUserConfiguration(userConfigName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Get the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri()); | |
UserConfiguration userConfig = client.getUserConfiguration(userConfigName); | |
System.out.println("Configuration Id: " + userConfig.getId()); | |
System.out.println("Configuration Name: " + userConfig.getUserConfigurationName().getName()); | |
System.out.println("Key value pairs:"); | |
for (String key : (String[]) userConfig.getDictionary().values().toArray()) { | |
System.out.println(key + ": " + userConfig.getDictionary().get(key).toString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = Utils.getAsposeEWSClient(); | |
System.out.println("Connected to Exchange 2010"); | |
// Get the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.getMailboxInfo().getInboxUri()); | |
UserConfiguration userConfig = client.getUserConfiguration(userConfigName); | |
userConfig.setId(null); | |
// Update User Configuration | |
userConfig.getDictionary().put("key1", "new-value1"); | |
client.updateUserConfiguration(userConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxURI = "http://ex2003/exchange/administrator"; // WebDAV | |
ExchangeClient client = new ExchangeClient(mailboxURI, "username", "password", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
// List all messages from Inbox folder | |
System.out.println("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(mailboxInfo.getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Move message to "Processed" folder, after processing certain messages based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("process this message") == true) { | |
// Move it | |
client.moveMessage(msgInfo, client.getMailboxInfo().getRootUri() + "/Processed/" + msgInfo.getSubject()); | |
System.out.println("Message moved...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
// List all messages from Inbox folder | |
System.out.println("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(mailboxInfo.getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Move message to "Processed" folder, after processing certain messages | |
// based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("process this message") == true) { | |
// Move it | |
client.moveItem(msgInfo.getUniqueUri(), client.getMailboxInfo().getRootUri() + "/Processed/" + msgInfo.getSubject()); | |
System.out.println("Message moved...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to display the basic information | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
System.out.println("Subject: " + msgInfo.getSubject()); | |
System.out.println("From: " + msgInfo.getFrom().toString()); | |
System.out.println("To: " + msgInfo.getTo().toString()); | |
System.out.println("Message Size: " + msgInfo.getSize()); | |
System.out.println("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "Username", "password", "domain"); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo("otherUser@domain.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo("otherUser@domain.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.office365.com/Exchange.asmx", "username","password"); | |
java.util.List<String> uriList = java.util.Arrays.asList(client.listItems(client.getMailboxInfo().getCalendarUri())); | |
//Define the Extended Attribute Property Descriptor for searching purpose | |
//In this case, we have a K1 Long named property for Calendar item | |
UUID uuid = UUID.fromString("00020329-0000-0000-C000-000000000046"); | |
PropertyDescriptor propertyDescriptor = new PidNamePropertyDescriptor("K1", PropertyDataType.Integer32, uuid); | |
java.util.List<PropertyDescriptor> propertyDescriptors = java.util.Arrays.asList(new PropertyDescriptor[] { propertyDescriptor}); | |
IGenericList<MapiCalendar> mapiCalendarList = client.fetchMapiCalendar(uriList, propertyDescriptors); | |
for (MapiCalendar cal: mapiCalendarList) | |
{ | |
for (MapiNamedProperty namedProperty : (Iterable<MapiNamedProperty>) cal.getNamedProperties().getValues()) | |
{ | |
System.out.println(namedProperty.getNameId() + " = " + namedProperty.getInt32()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String folderName = "DesiredFolderName"; | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeFolderInfoCollection folders = client.listPublicFolders(); | |
ExchangeFolderPermissionCollection permissions = new ExchangeFolderPermissionCollection(); | |
ExchangeFolderInfo publicFolder = null; | |
try { | |
for (ExchangeFolderInfo folderInfo : folders) | |
if (folderInfo.getDisplayName().equals(folderName)) | |
publicFolder = folderInfo; | |
if (publicFolder == null) | |
System.out.println("public folder was not created in the root public folder"); | |
ExchangePermissionCollection folderPermissionCol = client.getFolderPermissions(publicFolder.getUri()); | |
for (ExchangeBasePermission perm : folderPermissionCol) { | |
ExchangeFolderPermission permission = (ExchangeFolderPermission) perm;//perm as ExchangeFolderPermission; | |
if (permission == null) | |
System.out.println("Permission is null."); | |
else { | |
System.out.println("User's primary smtp address: " + permission.getUserInfo().getPrimarySmtpAddress().toString()); | |
System.out.println("User can create Items: " + permission.canCreateItems()); | |
System.out.println("User can delete Items: " + permission.getDeleteItems()); | |
System.out.println("Is Folder Visible: " + permission.isFolderVisible()); | |
System.out.println("Is User owner of this folder: " + permission.isFolderOwner()); | |
System.out.println("User can read items: " + permission.getReadItems()); | |
} | |
} | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
//Get the Permissions for the Contacts Folder | |
ExchangePermissionCollection contactsPermissionCol = client.getFolderPermissions(mailboxInfo.getContactsUri()); | |
//Get the Permissions for the Calendar Folder | |
ExchangePermissionCollection calendarPermissionCol = client.getFolderPermissions(mailboxInfo.getContactsUri()); | |
} finally { | |
//Do the needful | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://servername/exchange/username", "username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now save the message in disk | |
client.saveMessage(strMessageURI, dataDir + msgInfo.getMessageId() + ".eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now save the message in disk | |
client.saveMessage(strMessageURI, dataDir + msgInfo.getMessageId() + ".eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage msg = client.fetchMessage(strMessageURI); | |
// Save message as MSG | |
msg.save(dataDir + msgInfo.getMessageId() + ".msg", SaveOptions.getDefaultMsg()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage msg = client.fetchMessage(strMessageURI); | |
// Save message as MSg | |
msg.save(dataDir + msgInfo.getMessageId() + ".msg", SaveOptions.getDefaultMsg()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
try { | |
OutputStream outputStream = new FileOutputStream(dataDir + msgInfo.getMessageId() + "_Out.eml"); | |
client.saveMessage(strMessageURI, outputStream); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
try { | |
OutputStream outputStream = new FileOutputStream(dataDir + msgInfo.getMessageId() + "_Out.eml"); | |
client.saveMessage(strMessageURI, outputStream); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String address = "firstname.lastname@aspose.com"; | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.aspose.com/ews/Exchange.asmx", "username", "password", "aspose.com"); | |
MailMessage message = new MailMessage(address, address, "Flagged message", "Make it nice and short, but descriptive. The description may appear in search engines' search results pages..."); | |
FollowUpOptions options = new FollowUpOptions(); | |
options.setVotingButtons("Yes;No;Maybe;Exactly!"); | |
client.send(message, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/username", "username", "password", "domain"); | |
// Create instance of type MailMessage | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("sender@domain.com")); | |
MailAddressCollection collTo = new MailAddressCollection(); | |
collTo.add("recipient@domain.com"); | |
msg.setTo(collTo); | |
msg.setSubject("Sending message from exchange server"); | |
msg.setHtmlBody("<h3>sending message from exchange server</h3>"); | |
// Send the message | |
client.send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create instance of type MailMessage | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("sender@domain.com")); | |
MailAddressCollection collTo = new MailAddressCollection(); | |
collTo.add("recipient@domain.com"); | |
msg.setTo(collTo); | |
msg.setSubject("Sending message from exchange server"); | |
msg.setHtmlBody("<h3>sending message from exchange server</h3>"); | |
// Send the message | |
client.send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
try { | |
String domain = "litwareinc.com"; | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create the meeting request | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
Date startDate = sdf.parse("10/05/2015 10:00:00"); | |
Date endDate = sdf.parse("10/05/2015 10:30:00"); | |
MailAddressCollection coll = new MailAddressCollection(); | |
coll.add("bob@" + domain); | |
Appointment app = new Appointment("meeting request", startDate, endDate, new MailAddress("administrator@" + domain), coll); | |
app.setSummary("meeting request summary"); | |
app.setDescription("description"); | |
// Create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("administrator@" + domain)); | |
msg.setTo(coll); | |
msg.isBodyHtml(true); | |
msg.setHtmlBody("<h3>HTML Heading</h3><p>Email Message detail</p>"); | |
msg.setSubject("meeting request"); | |
msg.addAlternateView(app.requestApointment(0)); | |
// Send the appointment | |
client.send(msg); | |
System.out.println("Appointment request sent"); | |
} catch (ExchangeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
try { | |
String domain = "litwareinc.com"; | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "username", "password", "domain"); | |
// Create the meeting request | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
Date startDate = sdf.parse("10/05/2015 10:00:00"); | |
Date endDate = sdf.parse("10/05/2015 10:30:00"); | |
MailAddressCollection coll = new MailAddressCollection(); | |
coll.add("bob@" + domain); | |
Appointment app = new Appointment("meeting request", startDate, endDate, new MailAddress("administrator@" + domain), coll); | |
app.setSummary("meeting request summary"); | |
app.setDescription("description"); | |
// Create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("administrator@" + domain)); | |
msg.setTo(coll); | |
msg.isBodyHtml(true); | |
msg.setHtmlBody("<h3>HTML Heading</h3><p>Email Message detail</p>"); | |
msg.setSubject("meeting request"); | |
msg.addAlternateView(app.requestApointment(0)); | |
// Send the appointment | |
client.send(msg); | |
System.out.println("Appointment request sent"); | |
} catch (ExchangeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.aspose.com/ews/Exchange.asmx/", "elon.musk", "mahlaka1982"); | |
MailMessage message1 = new MailMessage("john.kerry@aspose.com", "aspose-email.test3@aspose.com", "EMAILNET-34738 ", "EMAILNET-34738 Sync Folder Items"); | |
client.send(message1); | |
MailMessage message2 = new MailMessage("from@doamin.com", "to@domain.com", "EMAILNET-34738 - ", "EMAILNET-34738 Sync Folder Items"); | |
client.send(message2); | |
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
SyncFolderResult result = client.syncFolder(client.getMailboxInfo().getInboxUri(), null); | |
System.out.println(result.getNewItems().size()); | |
System.out.println(result.getChangedItems().size()); | |
System.out.println(result.getReadFlagChanged().size()); | |
System.out.println(result.getDeletedItems().length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create Exchange task object | |
ExchangeTask task = new ExchangeTask(); | |
// Set task subject | |
task.setSubject("Task 1 from Java"); | |
// Set task status to In progress | |
task.setStatus(ExchangeTaskStatus.InProgress); | |
// Create task on exchange | |
client.createTask(client.getMailboxInfo().getTasksUri(), task); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
// Parse all the tasks info in the list | |
for (ExchangeMessageInfo info : tasks) { | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.fetchTask(info.getUniqueUri()); | |
// Check if the current task fulfills the search criteria | |
if (task.getSubject().equals("test")) { | |
//Delete task from exchange | |
client.deleteTask(task.getUniqueUri(), DeleteTaskOptions.DeletePermanently); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeQueryBuilder queryBuilder = null; | |
MailQuery query = null; | |
ExchangeTask fetchedTask = null; | |
ExchangeMessageInfoCollection messageInfoCol = null; | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
//Set timezone for tasks | |
client.setTimezoneId("Central Europe Standard Time"); | |
//We use these status values for specifying in queries | |
Integer[] values = new Integer[] {ExchangeTaskStatus.Completed, ExchangeTaskStatus.Deferred, | |
ExchangeTaskStatus.InProgress, ExchangeTaskStatus.NotStarted, ExchangeTaskStatus.WaitingOnOthers}; | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
//Now retrieve the tasks with specific statuses | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().equals(status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
fetchedTask = client.fetchTask(messageInfoCol.get_Item(0).getUniqueUri()); | |
} | |
//retrieve all other than specified | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notEquals((int)status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
} | |
//specifying multiple criterion | |
Integer[] selectedStatuses = new Integer[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().in(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
//list all those which are not in our specified statuses | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notIn(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeTask task = new ExchangeTask(); | |
task.setSubject("EMAILNET-34759"); | |
task.setStatus(ExchangeTaskStatus.InProgress); | |
task.save(dataDir + "task_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MsgLoadOptions msgLoadOptions = new MsgLoadOptions(); | |
msgLoadOptions.setPreserveTnefAttachments(true); | |
// load task from .msg file | |
MailMessage eml = MailMessage.load(dataDir + "task.msg", msgLoadOptions); | |
eml.setFrom(new MailAddress("firstname.lastname@domain.com")); | |
eml.getTo().clear(); | |
eml.getTo().addItem(new MailAddress("firstname.lastname@domain.com")); | |
client.send(eml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
client.setTimezoneId("Central Europe Standard Time"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
// Parse all the tasks info in the list | |
for (ExchangeMessageInfo info : tasks) { | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.fetchTask(info.getUniqueUri()); | |
// Update the task status to NotStarted | |
task.setStatus(ExchangeTaskStatus.NotStarted); | |
// Set the task due date | |
Calendar cal = Calendar.getInstance(); | |
cal.set(2015, 6, 18, 20, 40); | |
task.setDueDate(cal.getTime()); | |
// Update task on exchange | |
client.updateTask(task); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "domain.com"); | |
// List all the contacts | |
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri()); | |
Contact contact = contacts[0]; | |
System.out.println("Name: " + contact.getDisplayName()); | |
contact.setDisplayName("David Ch"); | |
client.updateContact(contact); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
PersonalStorage pst = PersonalStorage.fromFile(""); | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com", "username", "password"); | |
final AtomicInteger numberOfProcessedItems = new AtomicInteger(0); | |
RestoreSettings rs = new RestoreSettings(); | |
rs.setBeforeItemCallback(new BeforeItemCallback() { | |
public void invoke(ItemCallbackArgs item) { | |
if (numberOfProcessedItems.get() >= 1) | |
{ | |
throw new AbortRestoreException(); | |
} | |
numberOfProcessedItems.incrementAndGet(); | |
} | |
}); | |
try { | |
client.restore(pst, rs); | |
} catch (AbortRestoreException e) { | |
System.out.println("1 resored"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxUri = "https://ex2010/exchangeews/exchange.asmx"; | |
String username = "test.exchange"; | |
String password = "pwd"; | |
String domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials); | |
//Create New Contact | |
Contact contact = new Contact(); | |
//Set general info | |
contact.setGender(Gender.Male); | |
contact.setDisplayName("Frank Lin"); | |
contact.setCompanyName("ABC Co."); | |
contact.setJobTitle("Executive Manager"); | |
//Add Phone numbers | |
PhoneNumber phoneNumber = new PhoneNumber(); | |
phoneNumber.setNumber("123456789"); | |
phoneNumber.setCategory(PhoneNumberCategory.getHome()); | |
contact.getPhoneNumbers().add(phoneNumber); | |
//contact's associated persons | |
AssociatedPerson person = new AssociatedPerson(); | |
person.setName("Catherine"); | |
person.setCategory(AssociatedPersonCategory.getSpouse()); | |
contact.getAssociatedPersons().add(person); | |
person = new AssociatedPerson(); | |
person.setName("Bob"); | |
person.setCategory(AssociatedPersonCategory.getChild()); | |
contact.getAssociatedPersons().add(person); | |
person = new AssociatedPerson(); | |
person.setName("Merry"); | |
person.setCategory(AssociatedPersonCategory.getSister()); | |
contact.getAssociatedPersons().add(person); | |
//URLs | |
Url url = new Url(); | |
url.setCategory(UrlCategory.getBlog()); | |
url.setHref("www.blog.com"); | |
contact.getUrls().add(url); | |
url = new Url(); | |
url.setCategory(UrlCategory.getHomePage()); | |
url.setHref("www.homepage.com"); | |
contact.getUrls().add(url); | |
//Set contact's Email address | |
EmailAddress address = new EmailAddress(); | |
address.setAddress("Frank.Lin@Abc.com"); | |
address.setDisplayName("Frank Lin"); | |
address.setCategory(EmailAddressCategory.getCustom().getEmail1()); | |
try | |
{ | |
client.createContact(contact); | |
} | |
catch (Exception ex) | |
{ | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = null; | |
try { | |
client = EWSClient.getEWSClient("https://outlook.office365.com/exchangeews/exchange.asmx", "username", "password"); | |
Calendar calendar = Calendar.getInstance(); | |
Date startTime = calendar.getTime(); | |
calendar.add(java.util.Calendar.HOUR, 1); | |
Date endTime = calendar.getTime(); | |
String timeZone = "America/New_York"; | |
Appointment appointment = new Appointment("Room 121", startTime, endTime, | |
MailAddress.to_MailAddress("email1@aspose.com"), | |
MailAddressCollection.to_MailAddressCollection("email2@aspose.com")); | |
appointment.setTimeZone(timeZone); | |
appointment.setSummary("EMAILNET-35198 - ".concat(java.util.UUID.randomUUID().toString())); | |
appointment.setDescription("EMAILNET-35198 Ability to add Java event to Secondary Calendar of Office 365"); | |
// Create new calendar folder | |
client.createFolder(client.getMailboxInfo().getCalendarUri(), "new calendar", null, "IPF.Appointment"); | |
ExchangeFolderInfoCollection calendarSubFolders = client.listSubFolders(client.getMailboxInfo().getCalendarUri()); | |
String newCalendarFolderUri = calendarSubFolders.get_Item(0).getUri(); | |
// Appointment API with calendar folder URI | |
// Create Appointment | |
client.createAppointment(appointment, newCalendarFolderUri); | |
// Update Appointment | |
appointment.setLocation("Room 122"); | |
client.updateAppointment(appointment, newCalendarFolderUri); | |
// List Appointments | |
Appointment[] listAppointments = client.listAppointments(newCalendarFolderUri); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment, newCalendarFolderUri); | |
listAppointments = client.listAppointments(newCalendarFolderUri); | |
// Appointment API with context current calendar folder URI | |
client.setCurrentCalendarFolderUri(newCalendarFolderUri); | |
// Create Appointment | |
client.createAppointment(appointment); | |
appointment.setLocation("Room 122"); | |
// Update Appointment | |
client.updateAppointment(appointment); | |
// List Appointments | |
listAppointments = client.listAppointments(); | |
// List default calendar folder | |
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri()); | |
// Cancel Appointment | |
client.cancelAppointment(appointment); | |
listAppointments = client.listAppointments(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String email = "..."; | |
String password = "..."; | |
AutodiscoverService svc = new AutodiscoverService(); | |
svc.setCredentials(new NetworkCredential("username@domain.com", "password")); | |
IGenericDictionary<Integer,Object> userSettings = svc.getUserSettings(email, UserSettingName.ExternalEwsUrl).getSettings(); | |
String ewsUrl = (String)userSettings.get_Item(UserSettingName.ExternalEwsUrl); | |
System.out.println("Exchange Server Url: " + ewsUrl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com/exchangeews/Exchange.asmx", "username", "password", "domain.com"); | |
ExchangeFolderInfo folderInfo = client.createFolder("myfolder", ExchangeFolderType.Contact); | |
client.createContact(folderInfo.getUri(), new MapiContact("MapiContact", "foo@gmail.com")); | |
Contact contact = new Contact(); | |
contact.setDisplayName("Contact"); | |
client.createContact(folderInfo.getUri(), contact); | |
MapiContact[] myfolderContacts = client.listContacts(folderInfo.getUri()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/exchangeews/exchange.asmx", "your.username", "your.password"); | |
Calendar date = Calendar.getInstance(); | |
Calendar startTime = Calendar.getInstance(); | |
startTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY), 0, 0); | |
Calendar endTime = Calendar.getInstance(); | |
endTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY) + 1, 0, 0); | |
String timeZone = "America/New_York"; | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addMailAddress(new MailAddress("attendee_address@aspose.com", "Attendee")); | |
Appointment app = new Appointment("Room 112", startTime.getTime(), endTime.getTime(), new MailAddress("organizeraspose-email.test3@domain.com"), attendees); | |
app.setTimeZone(timeZone); | |
app.setSummary("NETWORKNET-34136" + UUID.randomUUID().toString()); | |
app.setDescription("NETWORKNET-34136 Exchange 2007/EWS: Provide support for Add/Update/Delete calendar items"); | |
String uid = client.createAppointment(app); | |
Appointment fetchedAppointment1 = client.fetchAppointment(uid); | |
app.setLocation("Room 115"); | |
app.setSummary("New summary for " + app.getSummary()); | |
app.setDescription("New Description"); | |
client.updateAppointment(app); | |
Appointment[] appointments1 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments1.length); | |
Appointment fetchedAppointment2 = client.fetchAppointment(uid); | |
System.out.println("Summary: " + fetchedAppointment2.getSummary()); | |
System.out.println("Location: " + fetchedAppointment2.getLocation()); | |
System.out.println("Description: " + fetchedAppointment2.getDescription()); | |
client.cancelAppointment(app); | |
Appointment[] appointments2 = client.listAppointments(); | |
System.out.println("Total Appointments: " + appointments2.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient(mailboxUri, username, password, domain); | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
builder.getAppointment().getStart().since(sdf.parse("10/05/2016 10:00:00")); | |
builder.getAppointment().getEnd().beforeOrEqual(sdf.parse("10/15/2016 10:00:00")); | |
MailQuery query = builder.getQuery(); | |
Appointment[] appointments = client.listAppointments(query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
builder = new ExchangeQueryBuilder(); | |
builder.getAppointment().isRecurring().equals(false); | |
MailQuery query = builder.getQuery(); | |
Appointment[]appointments = client.listAppointments(query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
int itemsPerPage = 5; | |
String subj = UUID.randomUUID().toString() + " - " + "Query 1"; | |
MailQueryBuilder queryBuilder = new MailQueryBuilder(); | |
queryBuilder.getSubject().contains(subj); | |
MailQuery query = queryBuilder.getQuery(); | |
List<ExchangeMessagePageInfo> pages = new ArrayList<ExchangeMessagePageInfo>(); | |
ExchangeMessagePageInfo pageInfo = client.listMessagesByPage(client.getMailboxInfo().getInboxUri(), | |
query, itemsPerPage); | |
pages.add(pageInfo); | |
int count = pageInfo.getItems().size(); | |
System.out.println("Total Count: " + count); | |
while (!pageInfo.getLastPage()) | |
{ | |
pageInfo = client.listMessagesByPage(client.getMailboxInfo().getInboxUri(), | |
query, itemsPerPage, pageInfo.getPageOffset() + 1); | |
pages.add(pageInfo); | |
count += pageInfo.getItems().size(); | |
} | |
System.out.println("Total Count: " + count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeQueryBuilder builder1 = new ExchangeQueryBuilder(); | |
builder1.getItemSize().greater(80000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ExchangeQueryBuilder queryBuilder = null; | |
MailQuery query = null; | |
ExchangeTask fetchedTask = null; | |
ExchangeMessageInfoCollection messageInfoCol = null; | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/exchangeews/exchange.asmx", "testUser", "pwd", "domain"); | |
//Set timezone for tasks | |
client.setTimezoneId("Central Europe Standard Time"); | |
//We use these status values for specifying in queries | |
Integer[] values = new Integer[] {ExchangeTaskStatus.Completed, ExchangeTaskStatus.Deferred, | |
ExchangeTaskStatus.InProgress, ExchangeTaskStatus.NotStarted, ExchangeTaskStatus.WaitingOnOthers}; | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
//Now retrieve the tasks with specific statuses | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().equals(status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
fetchedTask = client.fetchTask(messageInfoCol.get_Item(0).getUniqueUri()); | |
} | |
//retrieve all other than specified | |
for (int status : values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notEquals((int)status); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
} | |
//specifying multiple criterion | |
Integer[] selectedStatuses = new Integer[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().in(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); | |
//list all those which are not in our specified statuses | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().notIn(Arrays.asList(selectedStatuses)); | |
query = queryBuilder.getQuery(); | |
messageInfoCol = client.listMessages(client.getMailboxInfo().getTasksUri(), query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password"); | |
try | |
{ | |
ExchangeFolderInfoCollection folderInfoCol = client.listSubFolders(client.getMailboxInfo().getRootUri()); | |
for (ExchangeFolderInfo folderInfo : folderInfoCol) | |
{ | |
switch (folderInfo.getFolderType()) | |
{ | |
case ExchangeFolderType.Appointment: | |
// handle Appointment | |
break; | |
case ExchangeFolderType.Contact: | |
// handle Contact | |
break; | |
case ExchangeFolderType.Task: | |
// handle Task | |
break; | |
case ExchangeFolderType.Note: | |
// handle email message | |
break; | |
case ExchangeFolderType.StickyNote: | |
// handle StickyNote | |
break; | |
case ExchangeFolderType.Journal: | |
// handle Journal | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
finally | |
{ | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/exchange/ews.asmx", "username", "password"); | |
ExchangeMessageInfoCollection list = client.listMessages(client.getMailboxInfo().getDeletedItemsUri()); | |
System.out.println(list.get_Item(0).getMessageInfoType()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password"); | |
try { | |
//Define total number of items per page | |
int itemsPerPage = 2; | |
List<AppointmentPageInfo> pages = new List<AppointmentPageInfo>(); | |
AppointmentPageInfo pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage); | |
pages.addItem(pagedAppointmentCol); | |
while (!pagedAppointmentCol.getLastPage()) | |
{ | |
pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage, pagedAppointmentCol.getPageOffset() + 1); | |
pages.addItem(pagedAppointmentCol); | |
} | |
//Verify the number of appointments retrieved using the paging support | |
int retrievedItems = 0; | |
for (AppointmentPageInfo folderCol : (Iterable<AppointmentPageInfo>) pages) | |
retrievedItems += folderCol.getItems().size(); | |
System.out.println("Total items retrieved: " + retrievedItems); | |
} finally { | |
if (client != null) | |
((IDisposable)client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxUri = "https://ex2010/exchangeews/exchange.asmx"; | |
String username = "test.exchange"; | |
String password = "pwd"; | |
String domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials); | |
//Listing Tasks from Server | |
client.setTimezoneId("Central Europe Standard Time"); | |
TaskCollection taskCollection = client.listTasks(client.getMailboxInfo().getTasksUri()); | |
//print retrieved tasks' details | |
int iTasksCount = taskCollection.size(); | |
for (int i = 0; i < iTasksCount; i++) { | |
ExchangeTask task = (ExchangeTask) taskCollection.get_Item(i); | |
System.out.println(task.getSubject()); | |
System.out.println(task.getStartDate()); | |
System.out.println(task.getDueDate()); | |
} | |
//Listing Tasks from server based on Query - Completed and In-Progress | |
Integer[] selectedStatuses = new Integer[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
ExchangeQueryBuilder queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.getTaskStatus().in(Arrays.asList(selectedStatuses)); | |
MailQuery query = queryBuilder.getQuery(); | |
taskCollection = client.listTasks(client.getMailboxInfo().getTasksUri(), query); | |
//print retrieved tasks' details | |
iTasksCount = taskCollection.size(); | |
for (int i = 0; i < iTasksCount; i++) { | |
ExchangeTask task = (ExchangeTask) taskCollection.get_Item(i); | |
System.out.println(task.getSubject()); | |
System.out.println(task.getStartDate()); | |
System.out.println(task.getDueDate()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://exchange.office365.com/Exchange.asmx", "username","password"); | |
java.util.List<String> uriList = java.util.Arrays.asList(client.listItems(client.getMailboxInfo().getCalendarUri())); | |
//Define the Extended Attribute Property Descriptor for searching purpose | |
//In this case, we have a K1 Long named property for Calendar item | |
UUID uuid = UUID.fromString("00020329-0000-0000-C000-000000000046"); | |
PropertyDescriptor propertyDescriptor = new PidNamePropertyDescriptor("K1", PropertyDataType.Integer32, uuid); | |
java.util.List<PropertyDescriptor> propertyDescriptors = java.util.Arrays.asList(new PropertyDescriptor[] { propertyDescriptor}); | |
IGenericList<MapiCalendar> mapiCalendarList = client.fetchMapiCalendar(uriList, propertyDescriptors); | |
for (MapiCalendar cal: mapiCalendarList) | |
{ | |
for (MapiNamedProperty namedProperty : (Iterable<MapiNamedProperty>) cal.getNamedProperties().getValues()) | |
{ | |
System.out.println(namedProperty.getNameId() + " = " + namedProperty.getInt32()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/exchangeews/exchange.asmx", "testUser", "pwd", "domain"); | |
// delegate calendar access permission | |
ExchangeDelegateUser delegateUser = new ExchangeDelegateUser("sharingfrom@domain.com", ExchangeDelegateFolderPermissionLevel.NotSpecified); | |
delegateUser.getFolderPermissions().setCalendarFolderPermissionLevel(ExchangeDelegateFolderPermissionLevel.Reviewer); | |
client.delegateAccess(delegateUser, "sharingfrom@domain.com"); | |
// Create invitation | |
MapiMessage mapiMessage = client.createCalendarSharingInvitationMessage("sharingfrom@domain.com"); | |
MailConversionOptions options = new MailConversionOptions(); | |
options.setConvertAsTnef(true); | |
MailMessage mail = mapiMessage.toMailMessage(options); | |
client.send(mail); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
try { | |
String domain = "litwareinc.com"; | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/exchangeews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create the meeting request | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
Date startDate = sdf.parse("10/05/2015 10:00:00"); | |
Date endDate = sdf.parse("10/05/2015 10:30:00"); | |
MailAddressCollection coll = new MailAddressCollection(); | |
coll.add("bob@" + domain); | |
Appointment app = new Appointment("meeting request", startDate, endDate, new MailAddress("administrator@" + domain), coll); | |
app.setSummary("meeting request summary"); | |
app.setDescription("description"); | |
// Create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.setFrom(new MailAddress("administrator@" + domain)); | |
msg.setTo(coll); | |
msg.isBodyHtml(true); | |
msg.setHtmlBody("<h3>HTML Heading</h3><p>Email Message detail</p>"); | |
msg.setSubject("meeting request"); | |
msg.addAlternateView(app.requestApointment(0)); | |
// Send the appointment | |
client.send(msg); | |
System.out.println("Appointment request sent"); | |
} catch (ExchangeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
try | |
{ | |
//Create a new Property | |
PidNamePropertyDescriptor pd = new PidNamePropertyDescriptor( | |
"MyTestProp", | |
PropertyDataType.String, | |
UUID.fromString("00020329-0000-0000-C000-000000000046")); | |
String value = "MyTestPropValue"; | |
//Create a message | |
MapiMessage message = new MapiMessage( | |
"from@domain.com", | |
"to@domain.com", | |
"EMAILNET-38844 - " + UUID.randomUUID().toString(), | |
"EMAILNET-38844 EWS: Support for create, retrieve and update Extended Attributes for Emails"); | |
//Set property on the message | |
message.setProperty(pd, value); | |
//append the message to server | |
String uri = client.appendMessage(message); | |
//Fetch the message from server | |
MapiMessage mapiMessage = client.fetchMapiMessage(uri, Arrays.asList(new PropertyDescriptor[] { pd })); | |
//Retrieve the property from the message | |
String fetchedValue = mapiMessage.getNamedProperties().get_Item(pd).getString(); | |
} | |
finally | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static ExchangeClient getExchangeClient() { | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username", "Username", "password", "domain"); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
// Create a message | |
MailMessage msg = new MailMessage("user@domain1.com", "user@domain2.com", "subject", "message"); | |
// Subscribe to the Inbox folder | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
client.subscribeFolder(client.getCurrentFolder().getName()); | |
// Append the newly created message | |
client.appendMessage(client.getCurrentFolder().getName(), msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
// Mark the message as read | |
client.removeMessageFlags(1, ImapMessageFlags.isRead()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
// Mark the message as read | |
client.changeMessageFlags(1, ImapMessageFlags.isRead()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
HttpProxy proxy = new HttpProxy("18.222.124.59", 8080); | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.setProxy(proxy); | |
client.selectFolder(ImapFolderInfo.IN_BOX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.domain.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(CopyMessagesFromOneFolderToAnother.class) + "IMAP/"; | |
final ImapClient client = new ImapClient("exchange.domain.com", "username", "password"); | |
try { | |
String folderName = dataDir + "EMAILNET-35242"; | |
if (!client.existFolder(folderName)) | |
client.createFolder(folderName); | |
try { | |
/* | |
* we need to check if this functionality is supported in case of Gmail. | |
* Use the getMoveSupported method for this purpose if required | |
* switch (serverType) { | |
* case TestServerType.Gmail: | |
* msAssert.isTrue(client.getMoveSupported()); | |
* break; | |
* } | |
*/ | |
//Select the Inbox folder of mailbox | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
//create a couple of messages that we'll append to the mailbox for testing | |
MailMessage message1 = new MailMessage("username@domain.com", "to@domain.com", "Message 1: Copying Multiple Messages on a Single API call", | |
"EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation."); | |
//Append the message to the server | |
String uniqueId1 = client.appendMessage(message1); | |
//Create another test message | |
MailMessage message2 = new MailMessage("username@domain.com", "to@domain.com", "Message 2: Copying Multiple Messages on a Single API call", | |
"EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation."); | |
//Append the message to the server | |
String uniqueId2 = client.appendMessage(message2); | |
//wait for some time so that we are sure that the messages have been appended to the mailbox | |
Thread.sleep(5000); | |
//Create a list of Unique IDs for appended messages | |
List<String> t = new List<String>(); | |
t.add(uniqueId1); | |
t.add(uniqueId2); | |
//Copy the list of messages to the destination folder | |
client.copyMessagesByUids(t, folderName, true); | |
//Now select the destination folder and verify that the messages have been copied to that folder | |
client.selectFolder(folderName); | |
ImapMessageInfoCollection msgsColl = client.listMessages(); | |
for (ImapMessageInfo msgInfo : msgsColl) | |
System.out.println(msgInfo.getSubject()); | |
} finally { | |
try { | |
client.deleteFolder(folderName); | |
} catch (java.lang.RuntimeException e) { | |
} | |
} | |
} finally { | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
client.deleteMessage(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
ImapMessageInfoCollection coll = client.listMessages(); | |
for (ImapMessageInfo msgInfo : coll) { | |
client.deleteMessage(msgInfo.getUniqueId()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
final ImapClient client = new ImapClient("exchange.domain.com", "username", "password"); | |
try { | |
try { | |
System.out.println(client.getUidPlusSupported()); | |
//select the Inbox folder of server | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
//The following list variable will contain messages UIDs | |
List<String> uidList = new List<String>(); | |
//Create 5 test messages and append them to server's mailbox | |
final int messageNumber = 5; | |
for (int i = 0; i < messageNumber; i++) { | |
//Create a new message | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", "Deleting Multiple Messages using ImapClient based on Message UIDs", | |
"EMAILNET-35226: Add ability in ImapClient to delete a set of messages"); | |
//Append the message to server | |
String uid = client.appendMessage(message); | |
//Add the message Unique Id to the storage list | |
uidList.add(uid); | |
} | |
//Retrieve the list of messages and verify the message count | |
final ImapMessageInfoCollection[] messageInfoCol = { null }; | |
messageInfoCol[0] = client.listMessages(); | |
System.out.println(messageInfoCol[0].size()); | |
//Now delete the messages using the messages' UIDs | |
client.deleteMessagesByUids(uidList, true); | |
client.commitDeletes(); | |
messageInfoCol[0] = client.listMessages(); | |
System.out.println(messageInfoCol[0].size()); | |
} finally { | |
} | |
} finally { | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
ImapMessageInfoCollection coll = client.listMessages(); | |
for (ImapMessageInfo msgInfo : coll) { | |
MailMessage eml = client.fetchMessage(msgInfo.getUniqueId()); //use the sequence number to fetch messages | |
eml.save(eml.getSubject() + ".eml", SaveOptions.getDefaultEml()); //save as EML | |
eml.save(eml.getSubject() + ".msg", SaveOptions.getDefaultMsg()); //save as MSG | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
ImapMessageInfoCollection coll = client.listMessages(); | |
for (int i = 1; i < coll.size(); i++) { | |
MailMessage eml = client.fetchMessage(i); //use the sequence number to fetch messages | |
eml.save(eml.getSubject() + ".eml", SaveOptions.getDefaultEml()); //save as EML | |
eml.save(eml.getSubject() + ".msg", SaveOptions.getDefaultMsg()); //save as MSG | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
ImapMessageInfoCollection coll = client.listMessages(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
ImapMessageInfoCollection coll = client.listMessages("Inbox", true); //any folder name can be used | |
for (ImapMessageInfo msgInfo : coll) { | |
System.out.println("Message Subject: " + msgInfo.getSubject()); | |
System.out.println("From: " + msgInfo.getSender().getAddress()); | |
System.out.println("Sent Date: " + msgInfo.getDate()); | |
System.out.println("Mime Message Id: " + msgInfo.getMessageId()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
ImapMessageInfoCollection coll = client.listMessages(5); //List 5 messages from the server | |
for (ImapMessageInfo msgInfo : coll) { | |
System.out.println("Message Subject: " + msgInfo.getSubject()); | |
System.out.println("From: " + msgInfo.getSender().getAddress()); | |
System.out.println("Sent Date: " + msgInfo.getDate()); | |
System.out.println("Mime Message Id: " + msgInfo.getMessageId()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Set conditions | |
ImapQueryBuilder builder = new ImapQueryBuilder(); | |
// Subject contains "Newsletter" | |
builder.getSubject().contains("Newsletter", true); | |
// Emails that arrived today | |
Calendar c2 = Calendar.getInstance(); | |
builder.getInternalDate().on(c2.getTime()); | |
// Build the query | |
MailQuery query = builder.getQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Connect and log in to IMAP | |
String host = "host"; | |
int port = 143; | |
String username = "user@host.com"; | |
String password = "password"; | |
ImapClient client = new ImapClient(host, port, username, password); | |
client.selectFolder("Inbox"); | |
// Set conditions | |
ImapQueryBuilder builder = new ImapQueryBuilder(); | |
// Subject contains "Newsletter" | |
builder.getSubject().contains("Newsletter"); | |
// Emails that arrived today | |
Calendar c2 = Calendar.getInstance(); | |
builder.getInternalDate().on(c2.getTime()); | |
// Build the query | |
MailQuery query = builder.getQuery(); | |
// Get list of messages | |
ImapMessageInfoCollection messages = client.listMessages(query); | |
for (ImapMessageInfo info : messages) { | |
System.out.println("Internal Date: " + info.getInternalDate().getTime()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Emails that arrived in last 7 days | |
Calendar c1 = Calendar.getInstance(); | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
builder.getInternalDate().before(c1.getTime()); | |
c1.set(2016, 04, 17, 14, 30, 0); | |
builder.getInternalDate().since(c1.getTime()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails from specific domain | |
builder.getFrom().contains("SpecificHost.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails sent to specific recipient | |
builder.getTo().contains("recipient"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
// Get emails from specific sender | |
builder.getFrom().contains("elon.musk@127.0.0.1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Emails that arrived today | |
Calendar c = Calendar.getInstance(); | |
c.set(2016, 04, 24, 14, 30, 0); | |
MailQueryBuilder builder = new MailQueryBuilder(); | |
builder.getInternalDate().on(c.getTime()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient("host.domain.com", 889, "username", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
//Number of items per page | |
int itemsPerPage = 5; | |
//Search string | |
String body = "2222222222222"; | |
//Define query builder | |
ImapQueryBuilder iqb = new ImapQueryBuilder(); | |
iqb.getBody().contains(body); | |
MailQuery query = iqb.getQuery(); | |
//Select the inbox folder where the messages with such body reside | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
//Search with normal list messages for reference - without paging | |
ImapMessageInfoCollection totalMessageInfoCol = client.listMessages(query); | |
List<ImapPageInfo> pages = new List<ImapPageInfo>(); | |
//search the messages with paging support | |
ImapPageInfo pageInfo = client.listMessagesByPage(ImapFolderInfo.IN_BOX, query, itemsPerPage); | |
pages.add(pageInfo); | |
while (!pageInfo.getLastPage()) { | |
pageInfo = client.listMessagesByPage(ImapFolderInfo.IN_BOX, query, pageInfo.getNextPage()); | |
pages.add(pageInfo); | |
} | |
int retrievedItems = 0; | |
//verify the number of items retrieved | |
for (ImapPageInfo folderCol : (Iterable<ImapPageInfo>) pages) | |
retrievedItems += folderCol.getItems().size(); | |
client.dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
//Connect and log in to IMAP | |
String host = "host"; | |
int port = 143; | |
String username = "user@host.com"; | |
String password = "password"; | |
ImapClient client = new ImapClient(host, port, username, password); | |
client.selectFolder("Inbox"); | |
//Set conditions | |
ImapQueryBuilder builder = new ImapQueryBuilder(); | |
//Subject contains "Newsletter" | |
builder.getSubject().contains("Newsletter"); | |
//Email that arrived today | |
builder.getInternalDate().on(new Date()); | |
//Build the query | |
MailQuery query = builder.getQuery(); | |
//Get list of messages | |
ImapMessageInfoCollection messages = client.listMessages(query); | |
System.out.println("Imap: " + messages.size() + " message(s) found."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapQueryBuilder queryBuilder = new ImapQueryBuilder(); | |
queryBuilder.hasFlags(ImapMessageFlags.keyword("custom1")); | |
queryBuilder.hasNoFlags(ImapMessageFlags.keyword("custom2")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapQueryBuilder builder = new ImapQueryBuilder(Charset.forName("UTF-8")); | |
builder.getSubject().contains("ğüşıöç", true); | |
MailQuery query = builder.getQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient(); | |
client.setHost("imap.gmail.com"); | |
client.setPort(993); | |
client.setUsername("username"); | |
client.setPassword("password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
ImapFolderInfoCollection folderInfoColl = client.listFolders(); | |
// Iterate through the collection to get folder info one by one | |
for (ImapFolderInfo folderInfo : folderInfoColl) { | |
// Folder name | |
System.out.println("Folder name is " + folderInfo.getName()); | |
// New messages in the folder | |
System.out.println("New message count: " + folderInfo.getNewMessageCount()); | |
// Check whether its readonly | |
System.out.println("Is it readonly? " + folderInfo.getReadOnly()); | |
// Total number of messages | |
System.out.println("Total number of messages " + folderInfo.getTotalMessageCount()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Initiate ImapClient with account's user name and password | |
ImapClient client = new ImapClient("server.domain.com", 587, "username", "password"); | |
// Set security options | |
client.setSecurityOptions(SecurityOptions.Auto); | |
try { | |
// Number of items per page | |
int itemsPerPage = 5; | |
List<ImapPageInfo> pages = new List<ImapPageInfo>(); | |
ImapPageInfo pageInfo = client.listMessagesByPage(itemsPerPage); | |
pages.addItem(pageInfo); | |
while (!pageInfo.getLastPage()) { | |
pageInfo = client.listMessagesByPage(pageInfo.getNextPage()); | |
pages.addItem(pageInfo); | |
} | |
//Verify the count of retrieved items | |
int retrievedItems = 0; | |
for (ImapPageInfo folderCol : (Iterable<ImapPageInfo>) pages) | |
retrievedItems += folderCol.getItems().size(); | |
System.out.println("Items retrieved: " + retrievedItems); | |
} finally { | |
if (client != null) | |
((IDisposable) client).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Initiate IMAP client with user name and password | |
ImapClient client = new ImapClient("host.domain.com", 587, "username", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
try { | |
//Create a test folder in the mailbox | |
String folderName = dataDir + "EMAILNET-35151"; | |
if (!client.existFolder(folderName)) | |
client.createFolder(folderName); | |
try { | |
//Append a new message to the created folder | |
MailMessage message = new MailMessage("from@gmail.com", "to@gmail.com", "EMAILNET-35151 - ", "EMAILNET-35151 ImapClient: Provide option to Move Message"); | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
String uniqueId = client.appendMessage(ImapFolderInfo.IN_BOX, message); | |
//Verify that the message is added | |
ImapMessageInfoCollection messageInfoCol1 = client.listMessages(); | |
//move the message to the created folder using its unique id | |
client.moveMessage(uniqueId, folderName); | |
//this is necessary to complete the transaction | |
client.commitDeletes(); | |
//select the created folder | |
client.selectFolder(folderName); | |
//verify that the message is moved to the new folder | |
messageInfoCol1 = client.listMessages(); | |
//verify that the message is moved from the source folder | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
messageInfoCol1 = client.listMessages(); | |
} finally { | |
try { | |
client.deleteFolder(folderName); | |
} catch (java.lang.RuntimeException e) { | |
} | |
} | |
} finally { | |
if (client != null) | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create a message | |
MailMessage message = new MailMessage("user@domain1.com", "user@domain2.com", "subject", "message"); | |
ImapClient client = new ImapClient("host.domain.com", 587, "username", "password"); | |
//Append the message to mailbox | |
String uid = client.appendMessage(ImapFolderInfo.IN_BOX, message); | |
//Add custom flags to the added message | |
client.addMessageFlags(uid, ImapMessageFlags.op_BitwiseOr( | |
ImapMessageFlags.keyword("custom1") | |
,ImapMessageFlags.keyword("custom1_0"))); | |
//Retrieve the messages for checking the presence of custom flag | |
client.selectFolder(ImapFolderInfo.IN_BOX); | |
ImapMessageInfoCollection messageInfos = client.listMessages(); | |
for (ImapMessageInfo inf: messageInfos) | |
{ | |
ImapMessageFlags[] flags = inf.getFlags().split(); | |
if (inf.containsKeyword("custom1")) | |
System.out.println("Keyword found"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient("imap.gmail.com", 993, "username", "password"); | |
ImapFolderInfoCollection folderInfoCol = client.listFolders("*"); | |
System.out.println("Extended List Supported: " + client.getExtendedListSupported()); | |
for (ImapFolderInfo folderInfo : folderInfoCol) { | |
switch (folderInfo.getName()) { | |
case "[Gmail]/All Mail": | |
System.out.println("Has Children: " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Bin": | |
System.out.println("Bin has children? " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Drafts": | |
System.out.println("Drafts has children? " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Important": | |
System.out.println("Important has Children? " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Sent Mail": | |
System.out.println("Sent Mail has Children? " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Spam": | |
System.out.println("Spam has Children? " + folderInfo.hasChildren()); | |
break; | |
case "[Gmail]/Starred": | |
System.out.println("Starred has Children? " + folderInfo.hasChildren()); | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
ImapClient client = new ImapClient("imap.gmail.com", 993, "username", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
System.out.println(client.getIdSupported()); | |
ImapIdentificationInfo serverIdentificationInfo1 = client.introduceClient(); | |
ImapIdentificationInfo serverIdentificationInfo2 = client.introduceClient(ImapIdentificationInfo.getDefaultValue()); | |
System.out.println(serverIdentificationInfo1 + "," + serverIdentificationInfo2); | |
System.out.println(serverIdentificationInfo1.getName()); | |
System.out.println(serverIdentificationInfo1.getVendor()); | |
System.out.println(serverIdentificationInfo1.getSupportUrl()); | |
System.out.println(serverIdentificationInfo1.getVersion()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
final ImapClient imapClient = new ImapClient("exchange.aspose.com", "username", "password"); | |
try { | |
final SmtpClient smtpClient = new SmtpClient("exchange.aspose.com", "username", "password"); | |
try { | |
final Semaphore semaphore = new Semaphore(1); | |
final ImapMonitoringEventArgs[] eventArgs = { null }; | |
imapClient.startMonitoring(new ImapMonitoringEventHandler() { | |
public void invoke(Object sender, ImapMonitoringEventArgs e) { | |
eventArgs[0] = e; | |
semaphore.release(); | |
} | |
}); | |
semaphore.acquire(); | |
Thread.sleep(5000); | |
smtpClient.send(new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34875", "EMAILNET-34875 Support for IMAP idle command")); | |
semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS); | |
if (eventArgs[0].getNewMessages().length == 1) | |
System.out.println("Message received."); | |
if (eventArgs[0].getNewMessages().length == 0) | |
System.out.println("Message received."); | |
smtpClient.send(new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34875 - ", "EMAILNET-34875 Support for IMAP idle command")); | |
semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS); | |
if (eventArgs[0].getNewMessages().length == 1) | |
System.out.println("Message received."); | |
if (eventArgs[0].getNewMessages().length == 0) | |
System.out.println("Message received."); | |
imapClient.stopMonitoring("Inbox"); | |
smtpClient.send(new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34875 - ", "EMAILNET-34875 Support for IMAP idle command")); | |
semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); | |
} finally { | |
if (smtpClient != null) | |
(smtpClient).dispose(); | |
} | |
} finally { | |
if (imapClient != null) | |
(imapClient).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
com.aspose.email.License license = new com.aspose.email.License(); | |
license.setLicense("Aspose.Email.Java.lic"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
com.aspose.email.License license = new com.aspose.email.License(); | |
license.setLicense(new java.io.FileInputStream("Aspose.Email.Java.lic")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Metered metered = new Metered(); | |
// Access the SetMeteredKey property and pass public and private keys as parameters | |
metered.setMeteredKey("*****", "*****"); | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(DisplayEmailInformation.class) + "email/"; | |
// Load the document from disk. | |
MailMessage eml = MailMessage.load(dataDir + "test.eml"); | |
//Get the page count of document | |
System.out.println(eml.getSubject()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg"); | |
for (MapiRecipient recipient:msg.getRecipients()) | |
{ | |
System.out.println("Recipient:" + recipient.getDisplayName()); | |
// Get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property | |
System.out.println("Response: "+ recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE).getString()); | |
// Get the PR_RECIPIENT_TRACKSTATUS_TIME property | |
System.out.println("Response time: {0}" + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME).getDateTime()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg"); | |
for (MapiRecipient recipient : msg.getRecipients()) { | |
System.out.println("Recipient: " + recipient.getDisplayName()); | |
// Get the PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY property | |
System.out.println("Delivery time: " + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY).getDateTime()); | |
// Get the PR_RECIPIENT_TRACKSTATUS_TIME_READ property | |
System.out.println("Read time" + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_READ).getDateTime()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2016, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date startDate = calendar.getTime(); | |
calendar.set(2016, Calendar.DECEMBER, 1); | |
Date endDate = calendar.getTime(); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addItem(new MailAddress("attendee_address@domain.com", "Attendee")); | |
Appointment app = new Appointment("Home", startDate, endDate, new MailAddress("organizer@domain.com", "Organizer"), attendees); | |
MailMessage msg = new MailMessage(); | |
msg.addAlternateView(app.requestApointment()); | |
MapiMessage mapi = MapiMessage.fromMailMessage(msg); | |
MapiCalendar cal = (MapiCalendar)mapi.toMapiMessageItem(); | |
cal.setReminderSet(true); | |
cal.setReminderDelta(58); //58 min before start of event | |
cal.setReminderFileParameter(dataDir + "Alarm01.wav"); | |
String savedFile = dataDir + "calendarWithAudioReminder_out.ics"; | |
cal.save(savedFile, AppointmentSaveFormat.Ics); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2016, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date startDate = calendar.getTime(); | |
calendar.set(2016, Calendar.DECEMBER, 1); | |
Date endDate = calendar.getTime(); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
attendees.addItem(new MailAddress("attendee_address@domain.com", "Attendee")); | |
Appointment app = new Appointment("Home", startDate, endDate, new MailAddress("organizer@domain.com", "Organizer"), attendees); | |
MailMessage msg = new MailMessage(); | |
msg.addAlternateView(app.requestApointment()); | |
MapiMessage mapi = MapiMessage.fromMailMessage(msg); | |
MapiCalendar cal = (MapiCalendar) mapi.toMapiMessageItem(); | |
cal.setReminderSet(true); | |
cal.setReminderDelta(45); //45 min before start of event | |
String savedFile = dataDir + "calendarWithDisplayReminder_out.ics"; | |
cal.save(savedFile, AppointmentSaveFormat.Ics); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create the appointment | |
MapiCalendar appointment = new MapiCalendar(); | |
appointment.setLocation("LAKE ARGYLE WA 6743"); | |
appointment.setSubject("Appointment"); | |
appointment.setBody("This is a very important meeting"); | |
Date startDate = null; | |
Calendar cal = GregorianCalendar.getInstance(); | |
cal.set(2016, 10, 2); | |
startDate = cal.getTime(); | |
Date endDate = null; | |
cal = GregorianCalendar.getInstance(); | |
cal.set(2016, 10, 3); | |
endDate = cal.getTime(); | |
appointment.setStartDate(startDate); | |
appointment.setEndDate(endDate); | |
appointment.save(dataDir + "CalendarItem_out.ics", AppointmentSaveFormat.Ics); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "messageMapi.msg"); | |
for (MapiRecipient rec : msg.getRecipients()) | |
{ | |
System.out.println(rec.getRecipientTrackStatus()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create the appointment | |
MapiCalendar appointment = new MapiCalendar(); | |
appointment.save(dataDir + "CalendarItemAsMSG_out.ics", AppointmentSaveFormat.Ics); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(CreateAndSaveOutlookMessageFile.class) + "outlook/"; | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "MapiTask.msg"); | |
MhtSaveOptions opt = SaveOptions.getDefaultMhtml(); | |
opt.setMhtFormatOptions(MhtFormatOptions.RenderTaskFields | MhtFormatOptions.WriteHeader); | |
opt.getFormatTemplates().clear(); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.SUBJECT, "<span class='headerLineTitle'>Subject:</span><span class='headerLineText'>{0}</span><br/>"); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.ACTUAL_WORK, "<span class='headerLineTitle'>Actual Work:</span><span class='headerLineText'>{0}</span><br/>"); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.TOTAL_WORK, "<span class='headerLineTitle'>Total Work:</span><span class='headerLineText'>{0}</span><br/>"); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.STATUS, "<span class='headerLineTitle'>Status:</span><span class='headerLineText'>{0}</span><br/>"); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.OWNER, "<span class='headerLineTitle'>Owner:</span><span class='headerLineText'>{0}</span><br/>"); | |
opt.getFormatTemplates().add(MhtTemplateName.Task.PRIORITY, "<span class='headerLineTitle'>Priority:</span><span class='headerLineText'>{0}</span><br/>"); | |
msg.save(dataDir + "MapiTask_out.mht", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage msg = MailMessage.load(dataDir + "message.msg"); | |
MapiConversionOptions options = new MapiConversionOptions(); | |
MapiMessage ae_mapi = MapiMessage.fromMailMessage(msg, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage msg = MailMessage.load(dataDir + "message.msg"); | |
MapiConversionOptions options = new MapiConversionOptions(); | |
options.setUseBodyCompression(true); | |
MapiMessage ae_mapi = MapiMessage.fromMailMessage(msg, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = new MapiMessage( | |
"sender@test.com", | |
"recipient1@test.com; recipient2@test.com", | |
"Test Subject", | |
"This is a body of message."); | |
MailConversionOptions options = new MailConversionOptions(); | |
options.setConvertAsTnef(true); | |
MailMessage mail = msg.toMailMessage(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Create an instance of MailMessage class | |
MailMessage mailMsg = new MailMessage(); | |
// Set FROM field of the message | |
mailMsg.setFrom(new MailAddress("from@domain.com")); | |
// Create an instance of MailAddressCollection | |
MailAddressCollection addressCol = new MailAddressCollection(); | |
// Add an address to MailAddressCollection | |
addressCol.addMailAddress(new MailAddress("to@domain.com")); | |
// Set the MailAddressCollection as TO field of the message | |
mailMsg.setTo(addressCol); | |
// Set SUBJECT of the message | |
mailMsg.setSubject("creating an outlook message file"); | |
// Set BODY of the message | |
mailMsg.setBody("This message is created by Aspose.Email for Java"); | |
// Create an instance of MapiMessage class and pass MailMessage as argument | |
MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg); | |
// Path and file name where message file will be saved | |
String strMsgFile = dataDir + "message_out.msg"; | |
// Save the message (msg) file | |
outlookMsg.save(strMsgFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg"); | |
ForwardMessageBuilder builder = new ForwardMessageBuilder(); | |
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart); | |
MapiMessage forwardMsg = builder.buildResponse(originalMsg); | |
forwardMsg.save(dataDir + "forward_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg"); | |
ReplyMessageBuilder builder = new ReplyMessageBuilder(); | |
builder.setReplyAll(true); | |
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart); | |
builder.setResponseText( | |
"<p><b>Dear Friend,</b>" | |
+ "</p> I want to introduce my co-author and co-teacher. " | |
+ "<p><a href=\"www.google.com\">This is a first link</a></p>" | |
+ "<p><a href=\"www.google.com\">This is a second link</a></p>"); | |
MapiMessage replyMsg = builder.buildResponse(originalMsg); | |
replyMsg.save(dataDir + "reply_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(1990, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date birthday = calendar.getTime(); | |
calendar.set(2012, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date weddingDay = calendar.getTime(); | |
MapiContactEventPropertySet contactEventSet = new MapiContactEventPropertySet(); | |
contactEventSet.setBirthday(birthday); | |
contactEventSet.setWeddingAnniversary(weddingDay); | |
MapiContact contact = new MapiContact(); | |
contact.setEvents(contactEventSet); | |
contact.save(dataDir + "Contact_out.msg", ContactSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiContact contact = new MapiContact(); | |
//Set different properties of this Contact Item. | |
//Set Name properties using MapiContactNamePropertySet | |
MapiContactNamePropertySet NamePropSet = new MapiContactNamePropertySet(); | |
NamePropSet.setSurname("Mellissa"); | |
NamePropSet.setGivenName("MacBeth"); | |
contact.setNameInfo(NamePropSet); | |
//Set professional properties using MapiContactProfessionalPropertySet | |
MapiContactProfessionalPropertySet ProfPropSet = new MapiContactProfessionalPropertySet(); | |
ProfPropSet.setTitle("Account Representative"); | |
ProfPropSet.setCompanyName("Contoso Ltd."); | |
ProfPropSet.setOfficeLocation("36/2529"); | |
contact.setProfessionalInfo(ProfPropSet); | |
//Telephones | |
MapiContactTelephonePropertySet Telephone = new MapiContactTelephonePropertySet(); | |
Telephone.setAssistantTelephoneNumber("(831) 758-7214"); | |
Telephone.setBusiness2TelephoneNumber("(831) 759-2518"); | |
Telephone.setBusinessTelephoneNumber("(831) 758-7285"); | |
Telephone.setCallbackTelephoneNumber("(831) 758-7321 (After hours"); | |
Telephone.setCarTelephoneNumber("(831) 758-7201"); | |
Telephone.setCompanyMainTelephoneNumber("(831) 758-7368"); | |
Telephone.setHome2TelephoneNumber("(831) 758-7256"); | |
Telephone.setHomeTelephoneNumber("(831) 758-7257"); | |
Telephone.setIsdnNumber("(831) 758-7381"); | |
Telephone.setMobileTelephoneNumber("(831) 758-7368"); | |
Telephone.setOtherTelephoneNumber("(831) 758-7201"); | |
Telephone.setPagerTelephoneNumber("(831) 758-7368"); | |
Telephone.setPrimaryTelephoneNumber("(831) 758-7334"); | |
Telephone.setRadioTelephoneNumber("(831) 758-7234"); | |
Telephone.setTelexNumber("(831) 758-7408"); | |
Telephone.setTtyTddPhoneNumber("(800) 806-4474"); | |
contact.setTelephones(Telephone); | |
//Set Physical Address using MapiContactPhysicalAddress and MapiContactPhysicalAddressPropertySet | |
MapiContactPhysicalAddress PhysAddrss = new MapiContactPhysicalAddress(); | |
PhysAddrss.setPostOfficeBox("144 Hitchcock Rd, Salinas, CA 93908"); | |
MapiContactPhysicalAddressPropertySet PhysAddrPropSet = new MapiContactPhysicalAddressPropertySet(); | |
PhysAddrPropSet.setWorkAddress(PhysAddrss); | |
contact.setPhysicalAddresses(PhysAddrPropSet); | |
//Set email information using MapiContactElectronicAddress and MapiContactElectronicAddressPropertySet | |
MapiContactElectronicAddress email = new MapiContactElectronicAddress(); | |
email.setAddressType("SMTP"); | |
email.setDisplayName("Melissa MacBeth (mellissa@contoso.com)"); | |
email.setEmailAddress("melissa@contoso.com"); | |
MapiContactElectronicAddressPropertySet ElecAddrPropSet = new MapiContactElectronicAddressPropertySet(); | |
ElecAddrPropSet.setEmail1(email); | |
contact.setElectronicAddresses(ElecAddrPropSet); | |
contact.save(dataDir + "OutlookContact_out.vcf", ContactSaveFormat.VCard); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiContact contact = new MapiContact("Sebastian Wright", "SebastianWright@dayrep.com"); | |
contact.setNameInfo(new MapiContactNamePropertySet("Bertha", "A.", "Buell")); | |
contact.setProfessionalInfo(new MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant")); | |
contact.getPersonalInfo().setPersonalHomePage("B2BTies.com"); | |
contact.getPhysicalAddresses().getWorkAddress().setAddress("Im Astenfeld 59 8580 EDELSCHROTT"); | |
contact.getElectronicAddresses().setEmail1(new MapiContactElectronicAddress("Experwas", "SMTP", "BerthaABuell@armyspy.com")); | |
contact.setTelephones(new MapiContactTelephonePropertySet("06605045265")); | |
//Set Photo Data | |
File fi = new File(dataDir + "Desert.jpg"); | |
byte[] fileContent = Files.readAllBytes(fi.toPath()); | |
MapiContactPhoto photo = new MapiContactPhoto(fileContent, MapiContactPhotoImageFormat.Jpeg); | |
contact.setPhoto(photo); | |
//Save as MSG | |
contact.save(dataDir + "Contact_out.msg", ContactSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "messageMapi.msg"); | |
MapiContact mapiContact = (MapiContact) msg.toMapiMessageItem(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiContact mapiContact = MapiContact.fromVCard(dataDir + "microsoft.vcf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiContact contactReadFromFile = MapiContact.fromVCard( "microsoft.vcf", StandardCharsets.UTF_8); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Set flag without dates | |
MapiMessage msg = createTestMessage(false); | |
FollowUpOptions options = new FollowUpOptions(); | |
options.setVotingButtons("Yes;No;Maybe;Exactly!"); | |
FollowUpManager.setOptions(msg, options); | |
msg.save(dataDir + "MapiMsgWithPoll_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static MapiMessage createTestMessage(boolean draft) { | |
MapiMessage msg = new MapiMessage("from@test.com", "to@test.com", "Flagged message", | |
"Make it nice and short, but descriptive. The description may appear in search engines' search results pages..."); | |
if (!draft) { | |
msg.setMessageFlags(msg.getFlags() ^ MapiMessageFlags.MSGFLAG_UNSENT); | |
} | |
return msg; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "MapiMsgWithPoll_out.msg"); | |
// This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category) | |
FollowUpOptions options = FollowUpManager.getOptions(msg); | |
// Voting buttons will be introduced as a string with semi-column as a separator | |
String votingButtons = options.getVotingButtons(); | |
System.out.println(votingButtons); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(DistributionList.class) + "outlook/"; | |
MapiDistributionListMemberCollection oneOffmembers = new MapiDistributionListMemberCollection(); | |
oneOffmembers.addItem(new MapiDistributionListMember("John R. Patrick", "JohnRPatrick@armyspy.com")); | |
oneOffmembers.addItem(new MapiDistributionListMember("Tilly Bates", "TillyBates@armyspy.com")); | |
MapiDistributionList dlist = new MapiDistributionList("Simple list", oneOffmembers); | |
dlist.setBody("Test body"); | |
dlist.setSubject("Test subject"); | |
dlist.setMileage("Test mileage"); | |
dlist.setBilling("Test billing"); | |
dlist.save(dataDir + "distlist_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "WithEmbeddedMsg.msg"); | |
msg.getAttachments().get_Item(0).save(dataDir + "attachment_out.msg"); | |
MapiMessage emb = MapiMessage.fromStream(new FileInputStream(dataDir + "WithEmbeddedMsg.msg")); | |
msg.getAttachments().insert(1, "new 11", emb); | |
msg.save(dataDir + "insertMSGAttachment_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "insertMSGAttachment_out.msg"); | |
msg.getAttachments().get_Item(0).save(dataDir + "attachment_out.msg"); | |
MapiMessage emb = MapiMessage.fromStream(new FileInputStream(dataDir + "insertMSGAttachment_out.msg")); | |
msg.getAttachments().replace(1, "new 1", emb); | |
msg.save(dataDir + "replaceEmbeddedMSGAttachment_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiNote note3 = new MapiNote(); | |
note3.setSubject("Blue color note"); | |
note3.setBody("This is a blue color note"); | |
note3.setColor(NoteColor.Blue); | |
note3.setHeight(500); | |
note3.setWidth(500); | |
note3.save(dataDir + "MapiNote_out.msg", NoteSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage note = MapiMessage.fromFile(dataDir + "MapiNote_out.msg"); | |
MapiNote note2 = (MapiNote) note.toMapiMessageItem(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiTask task = new MapiTask("To Do", "Just click and type to add new tasks", new Date(), new Date()); | |
Path p = FileSystems.getDefault().getPath("", dataDir + "Attach.txt"); | |
try | |
{ | |
task.getAttachments().add(dataDir + "TestAtt.txt", Files.readAllBytes(p)); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
task.save(dataDir + "MapiTask_out.msg", TaskSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2012, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date date = calendar.getTime(); | |
MapiTask testTask = new MapiTask("task with reminder", "this is a body", date, date); | |
testTask.setReminderSet(true); | |
testTask.setReminderTime(date); | |
testTask.setReminderFileParameter(dataDir + "Alarm01.wav"); | |
testTask.save(dataDir + "OutputTask_out.msg", TaskSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2016, Calendar.NOVEMBER, 1, 0, 0, 0); | |
Date startDate = calendar.getTime(); | |
calendar.set(2016, Calendar.DECEMBER, 1); | |
Date endDate = calendar.getTime(); | |
MapiTask task = new MapiTask("To Do", "Just click and type to add new task", startDate, endDate); | |
task.setPercentComplete(20); | |
task.setEstimatedEffort(2000); | |
task.setActualEffort(20); | |
task.setHistory(MapiTaskHistory.Assigned); | |
task.getUsers().setOwner("Darius"); | |
task.getUsers().setLastAssigner("Harkness"); | |
task.getUsers().setLastDelegate("Harkness"); | |
task.getUsers().setOwnership(MapiTaskOwnership.AssignersCopy); | |
String[] companies = { "company1", "company2", "company3" }; | |
task.setCompanies(companies); | |
String[] categories = { "category1", "category2", "category3" }; | |
task.setCategories(categories); | |
task.setMileage("Some test mileage"); | |
task.setBilling("Test billing information"); | |
task.getUsers().setDelegator("Test Delegator"); | |
task.setSensitivity(MapiSensitivity.Personal); | |
task.setStatus(MapiTaskStatus.Complete); | |
task.save(dataDir + "MapiTask_out.msg", TaskSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "MapiTask_out.msg"); | |
MapiTask task2 = (MapiTask) msg.toMapiMessageItem(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiTask task = MapiTask.fromVTodo(dataDir + "sample.ics"); | |
task.save(dataDir + "Test_out.msg", TaskSaveFormat.Msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage msg = new MapiMessage("from@test.com", "to@test.com", "Subj", "This is a message body"); | |
MapiMessage attachMsg = MapiMessage.fromFile(dataDir + "message.msg"); | |
msg.getAttachments().add("Weekly report", attachMsg); | |
msg.save(dataDir + "EmbededMessageAsAttachment.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
//Instantiate an MSG file to load an MSG file from disk | |
MapiMessage outlookMessageFile = MapiMessage.fromFile(dataDir + "WithEmbeddedMsg.msg"); | |
//Loop through the attachments collection associated with the MapiMessage object | |
for (int i = 0; i < outlookMessageFile.getAttachments().size(); i++) { | |
//Set a reference to the MapiAttachment object | |
MapiAttachment outlookMessageAttachment = (MapiAttachment) outlookMessageFile.getAttachments().get_Item(i); | |
//Display attachment type | |
System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag()); | |
//Display attached file name | |
System.out.println("File Name : " + outlookMessageAttachment.getLongFileName()); | |
//Save attachment to the disk | |
outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = MapiMessage.fromFile(dataDir + "EmbededMessageAsAttachment.msg"); | |
MapiMessage emb = mapi.getAttachments().get_Item(0).getObjectData().toMapiMessage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ParsingOutlookMessageFiles.class) + "outlook/"; | |
//Instantiate an MSG file to load an MSG file from disk | |
MapiMessage outlookMessageFile = MapiMessage.fromFile(dataDir + "message.msg"); | |
//Display sender's name | |
System.out.println("Sender Name : " + outlookMessageFile.getSenderName()); | |
//Display Subject | |
System.out.println("Subject : " + outlookMessageFile.getSubject()); | |
//Display Body | |
System.out.println("Body : " + outlookMessageFile.getBody()); | |
//Display Recipient's info | |
System.out.println("Recipients : \n"); | |
//Loop through the recipients collection associated with the MapiMessage object | |
for (int i = 0; i < outlookMessageFile.getRecipients().size(); i++) { | |
//Set a reference to the MapiRecipient object | |
MapiRecipient rcp = (MapiRecipient) outlookMessageFile.getRecipients().get_Item(i); | |
//Display recipient email address | |
System.out.println("Email : " + rcp.getEmailAddress()); | |
//Display recipient name | |
System.out.println("Name : " + rcp.getDisplayName()); | |
//Display recipient type | |
System.out.println("Recipient Type : " + rcp.getRecipientType()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Load the Outlook template (OFT) file in MailMessage's instance | |
MailMessage message = MailMessage.load(dataDir + "sample.oft"); | |
// Set the sender and recipients information | |
String senderDisplayName = "John"; | |
String senderEmailAddress = "john@abc.com"; | |
String recipientDisplayName = "William"; | |
String recipientEmailAddress = "william@xzy.com"; | |
message.setSender(new MailAddress(senderEmailAddress, senderDisplayName)); | |
message.getTo().addMailAddress(new MailAddress(recipientEmailAddress, recipientDisplayName)); | |
message.setHtmlBody(message.getHtmlBody().replace("DisplayName", "<b>" + recipientDisplayName + "</b>")); | |
// Set the name, location and time in email body | |
String meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>"; | |
String meetingTime = "<u>" + "Monday, June 28, 2010" + "</u>"; | |
message.setHtmlBody(message.getHtmlBody().replace("MeetingPlace", meetingLocation)); | |
message.setHtmlBody(message.getHtmlBody().replace("MeetingTime", meetingTime)); | |
// Save the message in MSG format and open in Office Outlook | |
MapiMessage mapimessage = MapiMessage.fromMailMessage(message); | |
mapimessage.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT); | |
mapimessage.save(dataDir + "Invitation.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = new MapiMessage("test@from.to", "test@to.to", "template subject", "Template body"); | |
try { | |
mapi.saveAsTemplate(dataDir + "mapiToOft.oft"); | |
} finally { | |
if (mapi != null) | |
((IDisposable) mapi).dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Load MSG file | |
MapiMessage message = MapiMessage.fromFile(dataDir + "message.msg"); | |
// Get all named MAPI properties | |
MapiPropertyCollection properties = message.getNamedProperties(); | |
// Read all properties in for loop | |
for (MapiNamedProperty mapiNamedProp : (Iterable<MapiNamedProperty>) properties.getValues()) { | |
// Read any specific property | |
switch (mapiNamedProp.getNameId()) { | |
case "TEST": | |
System.out.println(mapiNamedProp.getNameId() + " equals " + mapiNamedProp.getString()); | |
break; | |
case "MYPROP": | |
System.out.println(mapiNamedProp.getNameId() + " equals " + mapiNamedProp.getString()); | |
break; | |
default: | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mail = MailMessage.load(dataDir + "test.eml"); | |
MapiMessage mapi = MapiMessage.fromMailMessage(mail); | |
for (MapiNamedProperty namedProperty : (Iterable<MapiNamedProperty>) mapi.getAttachments().get_Item(0).getNamedProperties().getValues()) { | |
if (namedProperty.getNameId().equalsIgnoreCase("CustomAttGuid")) { | |
System.out.println("Equal.."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(RenderingContactInformationToMhtml.class) + "outlook/"; | |
//Load VCF Contact and convert to MailMessage for rendering to MHTML | |
MapiContact contact = MapiContact.fromVCard(dataDir + "ContactsSaqib Razzaq.vcf"); | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
contact.save(os, ContactSaveFormat.Msg); | |
MapiMessage msg = MapiMessage.fromStream(new ByteArrayInputStream(os.toByteArray())); | |
MailConversionOptions op = new MailConversionOptions(); | |
MailMessage eml = msg.toMailMessage(op); | |
//Prepare the MHT format options | |
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions(); | |
mhtSaveOptions.setCheckBodyContentEncoding(true); | |
mhtSaveOptions.setPreserveOriginalBoundaries(true); | |
mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.RenderVCardInfo | MhtFormatOptions.WriteHeader); | |
mhtSaveOptions.setRenderedContactFields(ContactFieldsSet.NameInfo | ContactFieldsSet.PersonalInfo | ContactFieldsSet.Telephones | ContactFieldsSet.Events); | |
eml.save(dataDir + "ContactsSaqib Razzaq_out.mhtml", mhtSaveOptions); | |
System.out.println("Execution Completed."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// PT_MV_FLOAT, PT_MV_R4, mv.float | |
MapiMessage msg = new MapiMessage(); | |
IList values = (IList) new ArrayList(); | |
values.addItem((float) 1); | |
values.addItem((float) 2); | |
msg.setProperty(new MapiProperty(0x23901004, values)); | |
//PT_MV_DOUBLE, PT_MV_R8 | |
values = (IList) new ArrayList(); | |
values.addItem((double) 1); | |
values.addItem((double) 2); | |
msg.setProperty(new MapiProperty(0x23901005, values)); | |
//PT_MV_APPTIME | |
values = (IList) new ArrayList(); | |
values.addItem(30456.34); | |
values.addItem(40655.45); | |
msg.setProperty(new MapiProperty(0x23901007, values)); | |
//PT_MV_I8, PT_MV_LONGLONG | |
values = (IList) new ArrayList(); | |
values.addItem((long) 30456); | |
values.addItem((long) 40655); | |
msg.setProperty(new MapiProperty(0x23901014, values)); | |
//PT_MV_SHORT, PT_MV_I2, mv.i2 | |
values = (IList) new ArrayList(); | |
values.addItem((short) 1); | |
values.addItem((short) 2); | |
msg.setProperty(new MapiProperty(0x23901002, values)); | |
//PT_MV_BOOLEAN | |
values = (IList) new ArrayList(); | |
values.addItem(true); | |
values.addItem(false); | |
msg.setProperty(new MapiProperty(0x2390100b, values)); | |
//PT_NULL | |
msg.setProperty(new MapiProperty(0x67400001, new byte[1])); | |
//PT_MV_LONG | |
values = (IList) new ArrayList(); | |
values.addItem((int) 4); | |
UUID uuid = UUID.randomUUID(); | |
MapiProperty property = new MapiProperty(msg.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); | |
msg.getNamedPropertyMapping().addNamedPropertyMapping(property, 0x00008028, uuid); | |
msg.setProperty(property); | |
//OR you can set the custom property (with the custom name) | |
MapiMessage message = new MapiMessage("sender@test.com", "recipient@test.com", "subj", "Body of test msg"); | |
values = (IList) new ArrayList(); | |
values.addItem((int) 4); | |
property = new MapiProperty(message.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); | |
message.addCustomProperty(property, "customProperty"); | |
//PT_FLOAT | |
//Please note that you need explicit cast to float value for this to work | |
float floatValue = 123.456F; | |
MapiMessage newMsg = new MapiMessage(); | |
long floatTag = newMsg.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_FLOAT); | |
UUID guid = UUID.randomUUID(); | |
MapiProperty newMapiProperty = new MapiProperty(floatTag, BitConverter.getBytesSingle(floatValue)); | |
newMsg.getNamedPropertyMapping().addNamedPropertyMapping(newMapiProperty,(long) 12, guid); | |
newMsg.setProperty(newMapiProperty); | |
boolean propertyIsOk = false; | |
for (MapiNamedProperty prop : (Iterable<MapiNamedProperty>) newMsg.getNamedProperties().getValues()) | |
{ | |
if (prop.getGuid().equals(guid)) | |
{ | |
float val = prop.getFloat(); | |
propertyIsOk = val == floatValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
//Instantiate an MSG file to load an MSG file from disk | |
MapiMessage outlookMessageFile = MapiMessage.fromFile(dataDir + "messageMapi.msg"); | |
//Get the MapiProperties collection | |
MapiPropertyCollection coll = outlookMessageFile.getProperties(); | |
//Access the MapiPropertyTag.PR_SUBJECT property | |
MapiProperty prop = (MapiProperty) coll.get_Item((Object) MapiPropertyTag.PR_SUBJECT); | |
//If the MapiProperty is not found, check the MapiProperty.PR_SUBJECT_W | |
//which is a unicode peer of MapiPropertyTag.PR_SUBJECT | |
if (prop == null) { | |
prop = (MapiProperty) coll.get_Item(MapiPropertyTag.PR_SUBJECT_W); | |
} | |
//If it cannot be found | |
if (prop == null) { | |
System.out.println("Mapi property could not be found."); | |
} else { | |
//Get the property data as string | |
String strSubject = prop.getString(); | |
System.out.println("Subject: " + strSubject); | |
} | |
//Read internet code page property | |
prop = (MapiProperty) coll.get_Item(MapiPropertyTag.PR_INTERNET_CPID); | |
if (prop != null) { | |
System.out.println("Code page: " + prop.getLong()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = new MapiMessage("from@doamin.com", "to@domain.com", "subject", "body"); | |
mapi.setBodyContent("<html><body><h1>This is the body content</h1></body></html>", BodyContentType.Html); | |
MapiMessage attachment = MapiMessage.fromFile(dataDir + "message.msg"); | |
mapi.getAttachments().add(dataDir + "Outlook2 Test subject.msg", attachment); | |
System.out.println("Before removal = " + mapi.getAttachments().get_Item(mapi.getAttachments().size() - 1).getProperties().size()); | |
mapi.getAttachments().get_Item(mapi.getAttachments().size() - 1).removeProperty(923467779);//Delete anyone property | |
System.out.println("After removal = " + mapi.getAttachments().get_Item(mapi.getAttachments().size() - 1).getProperties().size()); | |
mapi.save(dataDir + "EMAIL_589265.msg"); | |
MapiMessage mapi2 = MapiMessage.fromFile(dataDir + "EMAIL_589265.msg"); | |
System.out.println("Reloaded = " + mapi2.getAttachments().get_Item(mapi2.getAttachments().size() - 1).getProperties().size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// PT_MV_FLOAT, PT_MV_R4, mv.float | |
MapiMessage msg = new MapiMessage(); | |
IList values = (IList) new ArrayList(); | |
values.addItem((float) 1); | |
values.addItem((float) 2); | |
msg.setProperty(new MapiProperty(0x23901004, values)); | |
//PT_MV_DOUBLE, PT_MV_R8 | |
values = (IList) new ArrayList(); | |
values.addItem((double) 1); | |
values.addItem((double) 2); | |
msg.setProperty(new MapiProperty(0x23901005, values)); | |
//PT_MV_APPTIME | |
values = (IList) new ArrayList(); | |
values.addItem(30456.34); | |
values.addItem(40655.45); | |
msg.setProperty(new MapiProperty(0x23901007, values)); | |
//PT_MV_I8, PT_MV_LONGLONG | |
values = (IList) new ArrayList(); | |
values.addItem((long) 30456); | |
values.addItem((long) 40655); | |
msg.setProperty(new MapiProperty(0x23901014, values)); | |
//PT_MV_SHORT, PT_MV_I2, mv.i2 | |
values = (IList) new ArrayList(); | |
values.addItem((short) 1); | |
values.addItem((short) 2); | |
msg.setProperty(new MapiProperty(0x23901002, values)); | |
//PT_MV_BOOLEAN | |
values = (IList) new ArrayList(); | |
values.addItem(true); | |
values.addItem(false); | |
msg.setProperty(new MapiProperty(0x2390100b, values)); | |
//PT_NULL | |
msg.setProperty(new MapiProperty(0x67400001, new byte[1])); | |
//PT_MV_LONG | |
values = (IList) new ArrayList(); | |
values.addItem((int) 4); | |
UUID uuid = UUID.randomUUID(); | |
MapiProperty property = new MapiProperty(msg.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); | |
msg.getNamedPropertyMapping().addNamedPropertyMapping(property, 0x00008028, uuid); | |
msg.setProperty(property); | |
//OR you can set the custom property (with the custom name) | |
MapiMessage message = new MapiMessage("sender@test.com", "recipient@test.com", "subj", "Body of test msg"); | |
values = (IList) new ArrayList(); | |
values.addItem((int) 4); | |
property = new MapiProperty(message.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); | |
message.addCustomProperty(property, "customProperty"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(SetColorCategoryForOutlookMessageFile.class) + "outlook/"; | |
MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg"); | |
// Add category | |
FollowUpManager.addCategory(msg, "Purple Category"); | |
// Add another category | |
FollowUpManager.addCategory(msg, "Red Category"); | |
// Retrieve the list of available categories | |
IList categories = FollowUpManager.getCategories(msg); | |
// Remove the specified category | |
FollowUpManager.removeCategory(msg, "Red Category"); | |
// Clear all categories | |
FollowUpManager.clearCategories(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = MapiMessage.fromFile(dataDir + "message.msg"); | |
FollowUpManager.markAsCompleted(mapi); | |
mapi.save(dataDir + "MarkedCompleted_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = MapiMessage.fromFile(dataDir + "message.msg"); | |
FollowUpOptions options = FollowUpManager.getOptions(mapi); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MapiMessage mapi = MapiMessage.fromFile(dataDir + "message.msg"); | |
FollowUpManager.clearFlag(mapi); | |
mapi.save(dataDir + "FollowUpFlagRemoved_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mailMsg = new MailMessage(); | |
mailMsg.setSender(new MailAddress("AETest12@gmail.com")); | |
mailMsg.getTo().addMailAddress(new MailAddress("receiver@gmail.com")); | |
mailMsg.setBody("This message will test if follow up options can be added to a new mapi message."); | |
MapiMessage mapi = MapiMessage.fromMailMessage(mailMsg); | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2013, Calendar.MAY, 16, 14, 40, 0); | |
Date dtStartDate = calendar.getTime(); | |
calendar.set(2013, Calendar.MAY, 16, 16, 40, 0); | |
Date dtReminderDate = calendar.getTime(); | |
calendar.add(Calendar.DATE, 1); | |
Date dtDueDate = calendar.getTime(); | |
FollowUpOptions options = new FollowUpOptions("Follow Up", dtStartDate, dtDueDate, dtReminderDate); | |
FollowUpManager.setOptions(mapi, options); | |
mapi.save(dataDir + "SetFollowUpflag_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
MailMessage mailMsg = new MailMessage(); | |
mailMsg.setSender(new MailAddress("AETest12@gmail.com")); | |
mailMsg.getTo().addMailAddress(new MailAddress("receiver@gmail.com")); | |
mailMsg.setBody("This message will test if follow up options can be added to a new mapi message."); | |
MapiMessage mapi = MapiMessage.fromMailMessage(mailMsg); | |
mapi.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT); //mark this message as draft | |
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); | |
calendar.set(2013, Calendar.MAY, 16, 16, 40, 0); | |
Date dtReminderDate = calendar.getTime(); | |
//Add the follow up flag for recipient now | |
FollowUpManager.setFlagForRecipients(mapi, "Follow up", dtReminderDate); | |
mapi.save(dataDir + "SetFollowUpForRecipients_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
OlmStorage storage = new OlmStorage(dataDir + "OutlookforMac.olm"); | |
try { | |
for (OlmFolder folder : storage.getFolderHierarchy()) { | |
if (folder.hasMessages()) { | |
// extract messages from folder | |
for (MapiMessage msg : storage.enumerateMessages(folder)) { | |
System.out.println("Subject: " + msg.getSubject()); | |
} | |
} | |
// read sub-folders | |
if (folder.getSubFolders().size() > 0) { | |
for (OlmFolder subFolder : folder.getSubFolders()) { | |
System.out.println("Subfolder: " + subFolder.getName()); | |
} | |
} | |
} | |
} finally { | |
storage.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String dataDir = Utils.getSharedDataDir(AccessContactInformationFromPSTFile.class) + "outlook/"; | |
// Load the Outlook PST file | |
PersonalStorage pst = PersonalStorage.fromFile(dataDir + "SampleContacts.pst"); | |
// Get the Contacts folder | |
FolderInfo folderInfo = pst.getRootFolder().getSubFolder("Contacts"); | |
// Loop through all the contacts in this folder | |
MessageInfoCollection messageInfoCollection = folderInfo.getContents(); | |
for (int i = 0; i < messageInfoCollection.size(); i++) { | |
MessageInfo messageInfo = (MessageInfo) messageInfoCollection.get_Item(i); | |
// Get the contact information | |
MapiContact contact = (MapiContact) pst.extractMessage(messageInfo).toMapiMessageItem(); | |
// Display some contents on screen | |
System.out.println("Name: " + contact.getNameInfo().getDisplayName() + "\n"); | |
// Save to disk in MSG format | |
if (contact.getNameInfo().getDisplayName() != null) { | |
MapiMessage message = pst.extractMessage(messageInfo); // Get rid of illegal characters that cannot be used as a file name | |
String messageName = message.getSubject().replace(":", " ").replace("\\", " ").replace("?", " ").replace("/", " "); | |
message.save(dataDir + messageName + ".msg"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
public static void addMessagesInBulkMode() { | |
PersonalStorage pst = PersonalStorage.create(dataDir + "PersonalStorage.pst", FileFormatVersion.Unicode); | |
FolderInfo folder = pst.getRootFolder().addSubFolder("myInbox"); | |
folder.addMessages((IGenericEnumerable<MapiMessage>) new MapiMessageCollection(dataDir)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
private static void bulkAddFromAnotherPst() { | |
PersonalStorage pst = PersonalStorage.fromFile(dataDir + "SampleContacts.pst", false); | |
try { | |
PersonalStorage pstDest = PersonalStorage.fromFile(dataDir + "PersonalStorage.pst"); | |
try { | |
// Get the folder by name | |
FolderInfo folderInfo = pst.getRootFolder().getSubFolder("Contacts"); | |
MessageInfoCollection ms = folderInfo.getContents(); | |
// Get the folder by name | |
FolderInfo f = pstDest.getRootFolder().getSubFolder("myInbox"); | |
f.addMessages(folderInfo.enumerateMapiMessages()); | |
FolderInfo fi = pstDest.getRootFolder().getSubFolder("myInbox"); | |
MessageInfoCollection msgs = fi.getContents(); | |
} finally { | |
if (pstDest != null) | |
pstDest.dispose(); | |
} | |
} finally { | |
if (pst != null) | |
pst.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
PersonalStorage pst = PersonalStorage.create(dataDir + "AddFilesToPST_out.pst", FileFormatVersion.Unicode); | |
FolderInfo fi = pst.createPredefinedFolder("Inbox", StandardIpmFolder.Inbox); | |
fi.addFile(dataDir + "Report.xlsx", "IPM.Document.Excel.Sheet.8"); | |
pst.dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Date newDate(int y, int m, int d) { | |
java.util.Calendar c = java.util.Calendar.getInstance(); | |
c.setTimeInMillis(0); | |
c.set(y, m-1, d, 0, 0, 0); | |
return c.getTime(); | |
} | |
private static Date addHours(Date date, int amount) { | |
Calendar c = Calendar.getInstance(); | |
c.setTime(date); | |
c.add(Calendar.HOUR, amount); | |
return c.getTime(); | |
} | |
private static Date addDays(Date date, int amount) { | |
Calendar c = Calendar.getInstance(); | |
c.setTime(date); | |
c.add(Calendar.DAY_OF_MONTH, amount); | |
return c.getTime(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date startDate = addHours(newDate(2018, 7, 19), 12); | |
MapiCalendar calendar = new MapiCalendar("location1", "summary1", "description1", startDate, addHours(startDate, 1)); | |
MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence(); | |
recurrence.setRecurrencePattern(new MapiCalendarDailyRecurrencePattern()); | |
MapiCalendarRecurrencePattern pattern = recurrence.getRecurrencePattern(); | |
pattern.setPatternType(MapiCalendarRecurrencePatternType.Day); | |
pattern.setPeriod(1); | |
pattern.setEndType(MapiCalendarRecurrenceEndType.NeverEnd); | |
Date exceptionDate = addDays(startDate, 3); | |
MapiCalendarExceptionInfo exception = new MapiCalendarExceptionInfo(); | |
exception.setLocation("exceptionLocation"); | |
exception.setSubject("exceptionSubject"); | |
exception.setBody("exceptionBody"); | |
exception.setOriginalStartDate(exceptionDate); | |
exception.setStartDateTime(exceptionDate); | |
exception.setEndDateTime(addHours(exceptionDate, 5)); | |
exception.setAttachments(new MapiAttachmentCollection(calendar)); | |
exception.getAttachments().add("file.txt", new String("hello, world!").getBytes()); | |
pattern.getExceptions().addItem(exception); | |
pattern.getModifiedInstanceDates().addItem(exceptionDate); | |
pattern.getDeletedInstanceDates().addItem(exceptionDate); | |
calendar.setRecurrence(recurrence); | |
final PersonalStorage newPst = PersonalStorage.create(new ByteArrayOutputStream(), FileFormatVersion.Unicode); | |
try | |
{ | |
FolderInfo newFolder = newPst.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments); | |
newFolder.addMapiMessageItem(calendar); | |
} | |
finally { newPst.dispose(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Calendar cal = Calendar.getInstance(); | |
cal.set(Calendar.YEAR, 2016); | |
cal.set(Calendar.MONTH, Calendar.JANUARY); | |
cal.set(Calendar.DAY_OF_MONTH, 1); | |
Date startDate = cal.getTime(); | |
cal = Calendar.getInstance(); | |
cal.set(Calendar.YEAR, 2016); | |
cal.set(Calendar.MONTH, Calendar.FEBRUARY); | |
cal.set(Calendar.DAY_OF_MONTH, 1); | |
Date endDate = cal.getTime(); | |
// Create the appointment | |
MapiCalendar appointment = new MapiCalendar("LAKE ARGYLE WA 6743", "Appointment", "This is a very important meeting.", startDate, endDate); | |
// Create the meeting | |
MapiRecipientCollection attendees = new MapiRecipientCollection(); | |
attendees.add("ReneeAJones@armyspy.com", "Renee A. Jones", MapiRecipientType.MAPI_TO); | |
attendees.add("SzllsyLiza@dayrep.com", "Szollosy Liza", MapiRecipientType.MAPI_TO); | |
MapiCalendar meeting = new MapiCalendar("Meeting Room 3 at Office Headquarters", "Meeting", "Please confirm your availability.", startDate, | |
endDate, "CharlieKhan@dayrep.com", attendees); | |
PersonalStorage pst = PersonalStorage.create(dataDir + "MapiCalendarToPST_out.pst", FileFormatVersion.Unicode); | |
FolderInfo calendarFolder = pst.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments); | |
calendarFolder.addMapiMessageItem(appointment); | |
calendarFolder.addMapiMessageItem(meeting); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
// Contact #1 | |
MapiContact contact1 = new MapiContact("Sebastian Wright", "SebastianWright@dayrep.com"); | |
// Contact #2 | |
MapiContact contact2 = new MapiContact("Wichert Kroos", "WichertKroos@teleworm.us", "Grade A Investment"); | |
// Contact #3 | |
MapiContact contact3 = new MapiContact("Christoffer van de Meeberg", "ChristoffervandeMeeberg@teleworm.us", "Krauses Sofa Factory", "046-630-4614"); | |
// Contact #4 | |
MapiContact contact4 = new MapiContact(); | |
contact4.setNameInfo(new MapiContactNamePropertySet("Margaret", "J.", "Tolle")); | |
contact4.getPersonalInfo().setGender(MapiContactGender.Female); | |
contact4.setProfessionalInfo(new MapiContactProfessionalPropertySet("Adaptaz", "Recording engineer")); | |
contact4.getPhysicalAddresses().getWorkAddress().setAddress("4 Darwinia Loop EIGHTY MILE BEACH WA 6725"); | |
contact4.getElectronicAddresses().setEmail1(new MapiContactElectronicAddress("Hisen1988", "SMTP", "MargaretJTolle@dayrep.com")); | |
contact4.getTelephones().setBusinessTelephoneNumber("(08)9080-1183"); | |
contact4.getTelephones().setMobileTelephoneNumber("(925)599-3355"); | |
// Contact #5 | |
MapiContact contact5 = new MapiContact(); | |
contact5.setNameInfo(new MapiContactNamePropertySet("Matthew", "R.", "Wilcox")); | |
contact5.getPersonalInfo().setGender(MapiContactGender.Male); | |
contact5.setProfessionalInfo(new MapiContactProfessionalPropertySet("Briazz", "Psychiatric aide")); | |
contact5.getPhysicalAddresses().getWorkAddress().setAddress("Horner Strasse 12 4421 SAASS"); | |
contact5.getTelephones().setBusinessTelephoneNumber("0650 675 73 30"); | |
contact5.getTelephones().setHomeTelephoneNumber("(661)387-5382"); | |
// Contact #6 | |
MapiContact contact6 = new MapiContact(); | |
contact6.setNameInfo(new MapiContactNamePropertySet("Bertha", "A.", "Buell")); | |
contact6.setProfessionalInfo(new MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant")); | |
contact6.getPersonalInfo().setPersonalHomePage("B2BTies.com"); | |
contact6.getPhysicalAddresses().getWorkAddress().setAddress("Im Astenfeld 59 8580 EDELSCHROTT"); | |
contact6.getElectronicAddresses().setEmail1(new MapiContactElectronicAddress("Experwas", "SMTP", "BerthaABuell@armyspy.com")); | |
contact6.setTelephones(new MapiContactTelephonePropertySet("06605045265")); | |
PersonalStorage pst = PersonalStorage.create(dataDir + "MapiContactToPST_out.pst", FileFormatVersion.Unicode); | |
FolderInfo contactFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts); | |
contactFolder.addMapiMessageItem(contact1); | |
contactFolder.addMapiMessageItem(contact2); | |
contactFolder.addMapiMessageItem(contact3); | |
contactFolder.addMapiMessageItem(contact4); | |
contactFolder.addMapiMessageItem(contact5); | |
contactFolder.addMapiMessageItem(contact6); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String displayName1 = "Sebastian Wright"; | |
String email1 = "SebastianWright@dayrep.com"; | |
String displayName2 = "Wichert Kroos"; | |
String email2 = "WichertKroos@teleworm.us"; | |
String strEntryId1; | |
String strEntryId2; | |
// Create distribution list from contacts | |
PersonalStorage pst = PersonalStorage.create(dataDir + "pstFileName1_out.pst", FileFormatVersion.Unicode); | |
// Add the contact folder to the PST | |
FolderInfo contactFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts); | |
// Create contacts | |
strEntryId1 = contactFolder.addMapiMessageItem(new MapiContact(displayName1, email1)); | |
strEntryId2 = contactFolder.addMapiMessageItem(new MapiContact(displayName2, email2)); | |
// Create distribution list on the base of the created contacts | |
MapiDistributionListMember member1 = new MapiDistributionListMember(displayName1, email1); | |
member1.setEntryIdType(MapiDistributionListEntryIdType.Contact); | |
byte[] decodedBytes = Base64.decodeBase64(strEntryId1); | |
member1.setEntryId(decodedBytes); | |
MapiDistributionListMember member2 = new MapiDistributionListMember(displayName2, email2); | |
member2.setEntryIdType(MapiDistributionListEntryIdType.Contact); | |
decodedBytes = Base64.decodeBase64(strEntryId2); | |
member2.setEntryId(decodedBytes); | |
MapiDistributionListMemberCollection members = new MapiDistributionListMemberCollection(); | |
members.addItem(member1); | |
members.addItem(member2); | |
MapiDistributionList distributionList = new MapiDistributionList("Contact list", members); | |
distributionList.setBody("Distribution List Body!"); | |
distributionList.setSubject("Distribution List Subject!"); | |
// Add distribution list to PST | |
contactFolder.addMapiMessageItem(distributionList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
PersonalStorage pst = PersonalStorage.create(dataDir + "pstFileName2_out.pst", FileFormatVersion.Unicode); | |
// Add the contact folder to the PST | |
FolderInfo contactFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts); | |
MapiDistributionListMemberCollection oneOffmembers = new MapiDistributionListMemberCollection(); | |
oneOffmembers.addItem(new MapiDistributionListMember("John R. Patrick", "JohnRPatrick@armyspy.com")); | |
oneOffmembers.addItem(new MapiDistributionListMember("Tilly Bates", "TillyBates@armyspy.com")); | |
MapiDistributionList oneOffMembersList = new MapiDistributionList("Simple list", oneOffmembers); | |
contactFolder.addMapiMessageItem(oneOffMembersList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment